#include<stdio.h> #include<conio.h> void binary(unsigned int); // Prototype Decl
ID: 3763637 • Letter: #
Question
#include<stdio.h>
#include<conio.h>
void binary(unsigned int); // Prototype Declaration
int main()
{
unsigned int num;
printf("Enter Decimal Number : ");
scanf("%u", &num);
binary(num); // Function Call
getch();
}
//========================================================
void binary(unsigned int num)
{
unsigned int mask = 32768; //mask = [1000 0000 0000 0000]
printf("Binary Eqivalent : ");
while (mask > 0)
{
if ((num & mask) == 0)
printf("0");
else
printf("1");
mask = mask >> 1; // Right Shift
}
}
I have the source code, but i do not get quite what it wants. here are the questions that i do not get. can someone please help me to understand and solve the problem.
Intel PC:
Your C++ program should pass a char array and the integer to be converted to an assembly function and then display the char array. Assembly function return value is irrelevant since the function is modifying directly the memory where the char array is stored.
RaspberryPI:
Use the example for read and write to get the integer and write the processed 0's and 1's. You don't need to use an array. The output is generated one bit at a time.
Explanation / Answer
The code which is given is basically convert the Decimal numbers into Binary of 2 byets i.e. 16 bits.
Here is the description of the steps, how the code is working:
Enter Decimal Number:10
Binary Eqivalent : 0000000000001010
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.