#include #include /* * Diese Funktion gibt einen positiven 32Bit Integer * in Binardarstellung aus. * * Bsp.: * 511 => 00000000 00000000 00000001 11111111 * */ void print_bin_long(unsigned long int a) { unsigned long int high_one = 2147483648; //2^31 short int i; for( i = 0; i < 32; i++ ) { if( a & high_one ) { printf("1"); } else { printf("0"); } if( (i == 7) || (i == 15) || (i == 23) ) { printf(" "); } a <<= 1; } printf("\n"); } /* * Diese Funktion gibt einen positiven 16Bit Integer * in Binardarstellung aus. * * Bsp.: * 73 => 00000000 01001001 * */ void print_bin_short(unsigned short int a) { unsigned short int high_one = 32768; //2^15 short int i; for( i = 0; i < 16; i++ ) { if( a & high_one ) { printf("1"); } else { printf("0"); } if( i == 7 ) { printf(" "); } a <<= 1; } printf("\n"); } /* * Kompilieren mit: gcc -Wall -std=c99 print_bin.c -o print_bin * */ int main () { unsigned short int s = 73; unsigned long int l = 511; //Zahlen binaer darstellen! printf("short int %hd als Binaerzahl:\t", s); print_bin_short( s ); printf("long int %ld als Binaerzahl:\t", l); print_bin_long( l ); return 0; }