• Home
  • Blog
  • BC Program that Converts Integers to 32 Bit Two Complement C Programming Exercise

BC Program that Converts Integers to 32 Bit Two Complement C Programming Exercise

0 comments

Either submit the source code files (.cpp) under the “Submit Homework” menu option or demo the programs to the instructor during lab.

1. Using C++, write a program that converts an integer to 32-bit two’s complement. Add a space between every 8 bits. Do not use external libraries that provide the calculations automatically.

Example output
This program converts an integer to 32-bit two’s complement.

Enter an integer: 1999
Two’s complement: 00000000 00000000 00000111 11001111

Enter an integer: -65535
Two’s complement: 11111111 11111111 00000000 00000001

2. Using C++, write a program that converts an integer to a 32-bit IEEE-754 floating-point. Add a space to separate the exponent, exponent, and mantissa. Do not use external libraries that provide the calculations automatically.

Extra Credit: Have your program work with numbers that have fractions (digits to the right of the decimal point).

Example output
This program converts an integer to a 32-bit IEEE-754 floating-point.

Enter an integer: 1999
floating point: 0 10001001 11110011110000000000000

Enter an integer: -65535
floating point: 1 10001110 11111111111111100000000

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}