Skip to content

Instantly share code, notes, and snippets.

@vmesel
Created June 3, 2018 03:24
Show Gist options
  • Save vmesel/63b8a66c3c602f1cbd3df969d5a423c0 to your computer and use it in GitHub Desktop.
Save vmesel/63b8a66c3c602f1cbd3df969d5a423c0 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <arpa/inet.h>
// 192.168.0.133 -- 25 bits
int main(){
unsigned int var1, var2, var3;
unsigned int address = 0xc0a80085;
var1 = ~(0xffffffff >> 25);
// var1_>> = 0x7f
// var1_final = 0xffffff80
// address -- 0xc0a80085
var2 = (ntohl(address) & var1) + 1;
// var2_prim = ntohl(address) = 0x8500a8c0
// var2_sec = (ntohl(address) & var1) = 0x8500a880
// var2_final = (ntohl(address) & var1) + 1 = 0x8500a881
var3 = (1 << (32 - 25));
// var3 = (32 - 25) = 7
// var3 = (1 << 7) = 0x80
printf("%x", var3);
}
// var3 = (1 << (32 - bits)) - 2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment