Bit Manipulations
In your class directory, create another directory called Binary.
In the Binary directory, write code for the exercises
below.
-
Write a program that prints out the size of an integer on your local
machine. Use the sizeof
operator.
- Write a program that inputs an integer N and prints out the binary
representation of N. Use bitwise operators to extract individual bits from N. Sample
execution:
Enter an integer value: 13
The binary representation of 13 is 0000 0000 0000 0000 0000 0000 0000 1101
- Write a program that inputs an integer N and prints out the
hexadecimal
representation of N. Use masks and bitwise operators to extract groups of
4 bits from N.
Enter an integer value: 17
The hexadecimal representation of 17 is 0x00000011
Submit a printed copy of your code and your sample output for
each of the three exercises.