Write a C program to display the binary, octal, and hexadecimalconversions of an
ID: 3610898 • Letter: W
Question
Write a C program to display the binary, octal, and hexadecimalconversions of an integer expression. for input accepteight-character strings whose first character is +, -, or a digitand whose remaining characters are all digits. Whenconverting from base 10 to another base, do not use any arithmeticoperators (+, -, *, /) and also do not use binary, octal, or hexconversion sequences to display the conversions. Allow theuser to enter an expression either interactively or on the commandline. Must be written in c and able to run on the gcccompilerExplanation / Answer
please rate - thanks does this work? #include #include int main() {char hex[6]={'A','B','C','D','E','F'}; int numbits,num,digits,shifted,i,j; numbits=sizeof(int)*8; //get number of bitsconverting printf("Enter integer you want to convert (0 when done): "); scanf("%d",&num); while(num!=0) {printf("hex: "); for(i=28;i>=0;i-=4) {shifted=num; //don't destroy original number shifted=shifted>>i; //shift to theright shifted=shifted&15; //use mask to get 4 rightmost bits; if(shifted=0;i--) {shifted=num; //don't destroy original number shifted=shifted>>i; //shift to theright shifted=shifted&1; //use mask to get rightmost bit printf("%d",shifted); //print the digit } printf(" "); //when done with all digits go to next line printf("octal: "); for(i=30;i>=0;i-=3) {shifted=num; //don't destroy original number shifted=shifted>>i; //shift to theright if(i==30) shifted=shifted&3; else shifted=shifted&7; //use mask to get rightmost bit printf("%d",shifted); //print the digit } printf(" "); //whendone with all digits skip 2 lines printf("Enter integer you want to convert (0when done): "); scanf("%d",&num); } getch(); return 0; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.