esdTeamsters
asked on
How to programmatically determine whether a given binary/decimal number contains a specific binary place value
I'm trying to find the most efficicent method for evaluating a given number and determining which binary place values it is made up of. For example:
168 = 1010 1000 (is made up of the '128', '32' and '8' bits)
My goal is to be able to return a boolean value for each place value, indicating whether it is contained within the given number. I'm hoping there may be a "built-in" method for doing this simpler than coding the math manually! Does anyone have any ideas? Thanks!
168 = 1010 1000 (is made up of the '128', '32' and '8' bits)
My goal is to be able to return a boolean value for each place value, indicating whether it is contained within the given number. I'm hoping there may be a "built-in" method for doing this simpler than coding the math manually! Does anyone have any ideas? Thanks!
Use the "AND" logical operator. For example:
If 168 AND 128 = 128 then
'128 bit is set
Else
'128 bit is not set
End If
If 168 AND 128 = 128 then
'128 bit is set
Else
'128 bit is not set
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the quick response! I'm testing it out right now...
ASKER
Outstanding! works great, frodoman. Wim_Bl, thanks for the input, but the article wasn't specific to what I was looking for - I'm already converting binary to decimal and vice versa.
Thanks again all!
Thanks again all!
Glad I could help.
this link should prove helpful, it converts decimal to binary and vice versa:
http://www.vb-helper.com/howto_decimal_to_binary.html
greetings