mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-21 21:11:57 +03:00
formatting source-code for 2829b58c98
This commit is contained in:
parent
2829b58c98
commit
6eeeaf3337
@ -5,12 +5,12 @@ uint32_t reverseBits(uint32_t n)
|
||||
uint i;
|
||||
for (i = 0; i < TotalBits; i++)
|
||||
{
|
||||
if ((n &
|
||||
(UINT32_C(1)
|
||||
<< i))) // if the bit on the ith position of 32 bit input is 1,
|
||||
// then proceed Further note the use of UINT32_C to convert
|
||||
// 1 to unsigned 32 bit int, since just 1 is treated as int
|
||||
// which cannot be shifted left more than 30 times
|
||||
if ((n & (UINT32_C(1)
|
||||
<< i))) // if the bit on the ith position of 32 bit input is
|
||||
// 1, then proceed Further note the use of UINT32_C to
|
||||
// convert 1 to unsigned 32 bit int, since just 1 is
|
||||
// treated as int which cannot be shifted left more
|
||||
// than 30 times
|
||||
reverse_int =
|
||||
reverse_int |
|
||||
(UINT32_C(1)
|
||||
|
@ -4,11 +4,12 @@ int hammingWeight(uint32_t n)
|
||||
int i, weight = 0;
|
||||
for (i = 0; i < TotalBits; i++)
|
||||
{
|
||||
if (n & (UINT32_C(1)
|
||||
<< i)) // if the bit on the ith position of 32 bit input is 1,
|
||||
// then proceed Further note the use of UINT32_C to
|
||||
// convert 1 to unsigned 32 bit int, as just 1 is treated
|
||||
// as int which cannot be shifted left more than 30 times
|
||||
if (n &
|
||||
(UINT32_C(1)
|
||||
<< i)) // if the bit on the ith position of 32 bit input is 1,
|
||||
// then proceed Further note the use of UINT32_C to
|
||||
// convert 1 to unsigned 32 bit int, as just 1 is treated
|
||||
// as int which cannot be shifted left more than 30 times
|
||||
weight += 1;
|
||||
}
|
||||
return weight;
|
||||
|
@ -7,7 +7,7 @@ int findComplement(int num)
|
||||
// standard size in memory, we cannot rely on size for that information.
|
||||
TotalBits++; // increment TotalBits till temp becomes 0
|
||||
temp >>= 1; // shift temp right by 1 bit every iteration; temp loses 1
|
||||
// bit to underflow every iteration till it becomes 0
|
||||
// bit to underflow every iteration till it becomes 0
|
||||
}
|
||||
int i,
|
||||
flipNumber =
|
||||
|
Loading…
Reference in New Issue
Block a user