Link to home
Start Free TrialLog in
Avatar of esdTeamsters
esdTeamstersFlag for United States of America

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!
Avatar of Wim_Bl
Wim_Bl
Flag of Belgium image

Hi,

this link should prove helpful, it converts decimal to binary and vice versa:
http://www.vb-helper.com/howto_decimal_to_binary.html

greetings
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
ASKER CERTIFIED SOLUTION
Avatar of frodoman
frodoman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of esdTeamsters

ASKER

Thanks for the quick response!  I'm testing it out right now...
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!
Glad I could help.