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

[Webinar] Streamline your web hosting managementRegister Today

x
 
frodomanConnect With a Mentor 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
 
Wim_BlCommented:
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
 
frodomanCommented:
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
esdTeamstersAuthor Commented:
Thanks for the quick response!  I'm testing it out right now...
0
 
esdTeamstersAuthor 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
 
frodomanCommented:
Glad I could help.
0
All Courses

From novice to tech pro — start learning today.