ip address - Converting subnet mask prefix with C -


i'd convert prefix /24 255.255.255.0 using bitwise operations.

i have tried using unsigned int so:

unsigned int mask = -(1 << 32 - prefix); 

i thinking of creating while loop adds 1 correct place , decrements 0.

all appreciated!

use

unsigned long mask = (0xffffffff << (32 - prefix)) & 0xffffffff;  printf("%lu.%lu.%lu.%lu\n", mask >> 24, (mask >> 16) & 0xff, (mask >> 8) & 0xff, mask & 0xff); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -