programming-examples/c/Bitwise/C Program to round Floor of integer to next Lower Power of 2.c

25 lines
531 B
C
Raw Normal View History

2019-11-15 12:59:38 +01:00
/*
* C Program to round floor of integer to next lower power of 2
*/
#include <stdio.h>
#define NUM_BITS_INT 32
int count = 0;
void main()
{
int temp, n, bit, i = 0;
printf("Enter a number : ");
scanf("%d", &n);
temp = n;
while (i < NUM_BITS_INT)
{
bit = temp & 0x80000000;
if (bit == -0x80000000)
{
bit = 1;
}
printf("%d", bit);
temp = temp << 1;
i++;
}
}