(3) Write a function that will print an integer in binary format. HINT: start at the highest order bit, which for a 4-by
Posted: Thu May 05, 2022 1:37 pm
In C please, Thank you
(3) Write a function that will print an integer in binary format. HINT: start at the highest order bit, which for a 4-byte integer would be bit 31. Mask off that bit (see if it is a 0 or 1), then print out either a 0 or 1 accordingly. Decrement bitnum until all bits have been printed out (while bitnum is greater than or equal to zero). void PrintBinary(int value){ printf("0b"); // prefix with Ob // if sizeof(int) ==4, starts at bit 31 int bitnum = sizeof(int) 8 - 1;
(3) Write a function that will print an integer in binary format. HINT: start at the highest order bit, which for a 4-byte integer would be bit 31. Mask off that bit (see if it is a 0 or 1), then print out either a 0 or 1 accordingly. Decrement bitnum until all bits have been printed out (while bitnum is greater than or equal to zero). void PrintBinary(int value){ printf("0b"); // prefix with Ob // if sizeof(int) ==4, starts at bit 31 int bitnum = sizeof(int) 8 - 1;