Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USE THE CODE BELOW SO THAT IT APPLIES TO THE PSEUDOCODE AND RUBIC BELOW IT #include /* prototype */ void ConvertDecimalToBinary(int); void ConvertDecimalToBinary(DecimalNum) { int

USE THE CODE BELOW SO THAT IT APPLIES TO THE PSEUDOCODE AND RUBIC BELOW IT

#include  /* prototype */ void ConvertDecimalToBinary(int); void ConvertDecimalToBinary(DecimalNum) { int bit1, bit2, bit3, bit4, bit5, bit6, bit7, bit8; bit8 = DecimalNum; bit7 = bit8 / 2; bit6 = bit7 / 2; bit5 = bit6 / 2; bit4 = bit5 / 2; bit3 = bit4 / 2; bit2 = bit3 / 2; bit1 = bit2 / 2; bit1 = (bit1 % 2) ? 1 : 0; bit2 = (bit2 % 2) ? 1 : 0; bit3 = (bit3 % 2) ? 1 : 0; bit4 = (bit4 % 2) ? 1 : 0; bit5 = (bit5 % 2) ? 1 : 0; bit6 = (bit6 % 2) ? 1 : 0; bit7 = (bit7 % 2) ? 1 : 0; bit8 = (bit8 % 2) ? 1 : 0; printf(" Decimal %d converts to binary %d%d%d%d%d%d%d%d ", DecimalNum,bit1,bit2,bit3,bit4,bit5,bit6,bit7,bit8); return; } int main(void) { int DecNum; int AskAgain = 1; printf("Decimal to binary convertor "); while (AskAgain) { printf("Please enter a decimal number between 0 and 255 "); scanf("%d", &DecNum); if (DecNum >= 0 && DecNum  

image text in transcribed

image text in transcribed

prototypes for ConvertDecimalToBinary and PrintBinary function ConvertDecimalToBinary 0 pass in input decimal number and array to hold binary number (8 cells 1 for each bit) In for loop, use right bitshift to divide by 2 In for loop, use a bitmask to determine if odd or even and ternary if to assign 1 or 0 to bit array function PrintBinary pass in binary number array Use for loop to print out each element of binary number array main nput loop Ask for decimal number to convert If entered number is not between 0 and 255, then print "You entered a number not between 0 and 255" and ask for input again If enterd number is between 0 and 255, then leave input loop Call ConvertDecimalToBinary0 Call PrintBinary0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions

Question

Persuading Your Audience Strategies for

Answered: 1 week ago