Phil Sutter <phil@xxxxxx> wrote: > What we need in b is 'ff ff ff 00' for a prefix length of 24. Your > suggested alternative does not compile, so I tried both options for the > closing brace: > > | htonl((1 << 24) - 1) > > This turns into '00 ff ff ff' for both LE and BE, the opposite of what > we need. > > | htonl((1 << 24)) - 1 > > This turns into '00 00 00 00' on LE and '00 ff ff ff' on BE. > > My code leads to correct result on either architecture and I don't see a > simpler way of doing it. htonl(~0u << (32 - i)) would work, assuming i > 0 and <= 32.