Well, *all* data in C (and any other language for that matter) is already in binary; you just have to know how to print it out that way. If you want to read in a string of characters (1 and 0) representing a binary number, you'd probably have to write a function to do it, since I don't know of any standard C functions for it. A while loop could do the job too, but a function would be better so you could re-use it
Something along the lines of:
int result = 0;
while (more characters)
result *= 2;
if (1 was read), result += 1;
loop
As for printing in hexadecimal, check the manpage for printf()
Your second question could work along the same lines as the first:
int result = 0;
while (more characters)
result *= 16; // since it's base-16
result += current_digit_value; // hex digit converted to an int
loop
Converting the character from hexadecimal notation to an integer is the only slightly tricky part; something like this maybe:
if ( digit >= '0' && digit <= '9' ) // if digit is between 0 and 9
value = digit - '0'; // subtract ascii value of '0' from digit; '0' - '0' = 0
else if ( digit >= 'a' && digit <= 'f' )
value = digit - 'a' + 10; // since 'a' - 'a' = 0, add 10 to get value of 'a', etc.