C > Miscellaneous
Represent digits
Represent digits #include
#define BITS 32 int main(int argc, char * argv[]) { int y = 0; int z = 0; if(argc != 2) { fprintf(stderr, "seedig DIGIT\n"); return 1; } sscanf(argv[1], "%i", &y); printf(" hex : %#x\n", y); printf(" octal : %#o\n", y); printf(" decimal : %d\n", y); printf(" binary : "); for(z = BITS - 1; z >= 0; z--) { printf("%c", '0' + ((y & (1 << z)) >> z)); if(!(z & 3)) printf(" "); } printf("\n"); return 0; }
C Codes
Beginners
C on Unix
Code Snippets
Data Structures
File Operations
Games Graphics
Gnu-Linux
Hardware
Mathematics
Miscellaneous
Small Programs
Sorting