GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


Binary Byte to ASCII String, Version 2 by DELTRON
// Binary Byte to ASCII String, Version 2 - Delt 1/19/05

#include <stdio.h>

void main(void)
{
    char c = (char)0xAA;
    char b[] = {"00000000"};

    for (int i=0,p=128; i<8; i++,p/=2) {if(c&p) b[i]='1';}

    printf("%X in HEX is %s in BINARY\n\n",(unsigned char)c,b);

}