converting numbers via bit dropping

L

lists

Hi,
I'm trying to figure out how to convert a number by dropping bits
higher than the range that I want. For example, I'd like to convert
248 (0000 0001 0001 1100) into 28 (0001 1100) by converting any bits
over the 8th one into a zero:

000 0001 0001 1100
^^^ ^^^^

Any suggestions?

Thanks,
Ryan
 
P

Patrick Gundlach

Hi,

I'm trying to figure out how to convert a number by dropping bits
higher than the range that I want. For example, I'd like to convert
248 (0000 0001 0001 1100) into 28 (0001 1100) by converting any bits

This should be 284, right?
over the 8th one into a zero:

000 0001 0001 1100
^^^ ^^^^

Any suggestions?

irb(main):001:0> 284 & 255
=> 28

HTH,

Patrick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,204
Messages
2,571,065
Members
47,672
Latest member
svaraho

Latest Threads

Top