hi
I'm trying to print in binary the data stored in a string..
here's the string:
char test[20];
strcpy(test, "any data");
so how to print the bits?
is there an escape sequence that i can use with printf to do that?
thanks
hi
I'm trying to print in binary the data stored in a string..
here's the string:
char test[20];
strcpy(test, "any data");
so how to print the bits?
is there an escape sequence that i can use with printf to do that?
thanks
take in each character,convert it into binary form, and output to the screen..
this function converts an integer into binary form and displays it...i leave it to you to modify this to print the string...it wont be difficult.Code:void bin(int a) { if(a/2==1) printf("1"); else bin(a/2); printf("%d",a%2); }
Code:>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.
hum are you sure about this function? this will work for numbers between 0 and 10...I guess I'll have to add a loop..
you will have to add a loop and yes, i am pretty much sure bout this function.hum are you sure about this function? this will work for numbers between 0 and 10...I guess I'll have to add a loop..
Code:>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.
You could do something with this bits_block.Originally Posted by majoubCode:int main(void) { const char test[] = "any data"; char binary [ (CHAR_BIT + 1) * sizeof test ]; puts(test); puts(bits_block(binary, test, sizeof test)); return 0; } /* my output any data 01100001-01101110-01111001-00100000-01100100-01100001-01110100-01100001-00000000 */
Last edited by Dave_Sinkula; 03-19-2005 at 12:34 PM. Reason: Added code.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*