Monday, 19 August 2013

Printing binary representation of a char in C

Printing binary representation of a char in C

I've been searching around for a decent example for a few days now and
seriously cant seem to find anything.
I want a really basic way to print out the binary representation of a
char. I can't seem to find and example code anywhere.
I assumed you could do it in a few lines but everything i find is overly
long and complex using lots of functions I haven't used before. atoi comes
up a lot but it's not standard.
Is there a simple function or simple way of writing a function to take a
char variable and then print out a binary representation?
Eg: char 'x' is the argument taken in by the function and "x is 0111 1000"
is printed out.
It's for a school assignment where I must take user input of a string and
print out the string in binary. I just need to get the basics of
converting a char to binary but i'm struggling at the moment.
Thanks!

No comments:

Post a Comment