Skip to content

Instantly share code, notes, and snippets.

@KristianLyng
Created February 11, 2013 23:02
Show Gist options
  • Select an option

  • Save KristianLyng/4758419 to your computer and use it in GitHub Desktop.

Select an option

Save KristianLyng/4758419 to your computer and use it in GitHub Desktop.
$ cat foo.c; gcc foo.c; ./a.out
#include <stdio.h>
static
void print_bitmask(int a) {
int i;
for (i=0;i<(sizeof(int) * 8);i++) {
if(a& ((int)1<<i)) putchar('1');
else putchar('0');
if((i+1)%8 ==0) putchar(' ');
}
}
main() {
int i = 16777343;
char *a = (unsigned char *)&i;
print_bitmask(i);
printf("IP: %d er %hhu.%hhu.%hhu.%hhu.\n",i, a[0], a[1], a[2], a[3]);
unsigned int foo2 = 0;
foo2 |= 127;
foo2 = foo2 << 8;
foo2 |= 0;
foo2 = foo2 << 8;
foo2 |= 0;
foo2 = foo2 << 8;
foo2 |= 1;
printf("foo2: %u\n", foo2);
}
11111110 00000000 00000000 10000000 IP: 16777343 er 127.0.0.1.
foo2: 2130706433
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment