# 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!
###### Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x

Commented:
A more generic form of my last posting:

function IsBitSet(TestValue as Integer, BitValue as Integer) as Boolean
Return ((TestValue AND BitValue)=BitValue)
0

Commented:
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
0

Commented:
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
0

Author Commented:
Thanks for the quick response!  I'm testing it out right now...
0

Author Commented:
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!
0

Commented: