I require a c algorithm to convert 255 decimal numbers to binary using 8 bits. The binary numbers must print to screen on execution. Char's must be used as well as number, remainder, divisor & answer.
thanks sully1
In a for loop print the values from 0 to 255 with an integer variable.
Along with that try to display the integer in terms of Char
For eg: int i=32;
printf("%c",i); // char "a" will be displayed.
Same way You can print chars and int. To print binary equivalent
try this way (take the value in temp variable)
while(i>0)
{
cout<<i%2;
i/=2;
} // printing Divider, reminder, quotient all things can be done
//here
As a special case for the ASCII values between 48 to 57
[ these ASCII values represents 0 to 9 ]
check with the If condition whether value is between above range, if so
then deduct 48 from it to get decimal equivalent and then Convert it to
Binary.
Does this cheers you ?
If you are trying to get the data from user for which you need to give
binary value, then get everything as char Array bcz it may be number like
112 which is 3 digit decimal integer. Down cast to Exact decimal & then
proceed as usual, In case single char then proceed directly.