From: Robert Klemme Date: 2008-05-07T02:10:08+09:00 Subject: Re: Conversion mask in hex to bit mask On 06.05.2008 13:29, Marcin Tyman wrote: > The issue is: how to convert hex mask to bit mask? For instance: > > I have 0xffff0000 -> it can be represent by 255.255.0.0 or by string > of bits - 16 Not sure what exactly you mean by this. Do you want to count 1's? Here are some things you can do: irb(main):001:0> c = 0xffff0000 => 4294901760 irb(main):002:0> c.to_s(2) => "11111111111111110000000000000000" irb(main):003:0> c.to_s(2).length => 32 Bit access: irb(main):004:0> c[0] => 0 irb(main):005:0> c[20] => 1 > My question is how to convert such hexes to bit mask (the 16 in above > example) Cheers robert