Here's the binary string:
01010010011000010110101001101100011010010110001101101000
Now break it up into bytes (a byte is 8 bits):
01010010 01100001 01101010 01101100 01101001 01100011 01101000
Now convert each byte from binary to base 10:
82 97 106 108 105 99 104
Look up the corresponding character for each number in the
ASCII table:
R a j l i c h
The string is the binary encoding of the character string
"Rajlich". :-) In other words, this is how a computer stores
the string "Rajlich."
Here's the program:
#include "stdio.h"
#include "string.h"
int main(int argc, char **argv) {
int i, j, c;
char *str = argc>1 ? argv[1] : strdup("Rajlich");
printf("%s -> ", str);
for (i=0; str[i]!='\0'; i++)
for (c=str[i], j=0; j<8; j++, c<<=1)
printf("%d", c&0x80 ? 1 : 0);
printf("\n");
}
|