The following C code can be used, to get a reverse binary representation of a char character:
#include <stdio.h>
#include <string.h>
/*
* This function returns a string in reverse binary order.
*/
void
char_to_bin_reverse(char *c)
{
int i, bin;
char ch;
while ((ch = *c++) != NULL) {
printf("ch's char value: %c\n", ch);
printf("ch's decimal value: %d\n", ch);
printf("ch's binary value: ");
for (i = 0; i < 8; i++) {
bin = ((ch >> i) & 1) ? 1 : 0;
printf("%d", bin);
}
printf("\n");
} /* while */
}
int
main()
{
char *msg = "Hello, world!";
printf("char to binary reverse:\n");
char_to_bin_reverse(msg);
printf("\n");
return(0);
}