Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve bit values from a byte 2

Status
Not open for further replies.

karenmierkalns

Programmer
May 10, 2001
54
0
0
CA
I may be overlooking a simple concept, but I seem to be stuck on this. I need to retrieve the 8 bits from a given byte. How do you do this? I am currently using Asc() and Chr(). However, I don't think this is correct.

Any information that I can find simply says that there ARE 8 bits in a given byte, but not HOW to retrieve the values of the bits.

Thanks a whole lot. - Karen
 
given a byte is a number if you do this
Dim bByte as Byte

bBtye = 'some number

If (bByte AND 128) then '8th bit is set
If (bByte AND 64) then '7th bit is set
If (bByte AND 32) then '6th bit is set
If (bByte AND 16) then '5th bit is set
If (bByte AND 8) then '4th bit is set
If (bByte AND 4) then '3rd bit is set
If (bByte AND 2) then '2nd bit is set
If (bByte AND 1) then '1st bit is set
 
Thank you very much! I will have to verify if certain bits are set, so the information you (SemperFiDownUnda) suggested will come in handy.
The thread you recommended (vb5prgmr) is very helpful (and seems to be the answer to my question)! Specifically:

---------
You will have to convert the text string to its ascii value then to its binary value.

"this is a test" = 8 bits for 1 byte per character

In binary:
this _01110100 01101000 01101001 01110011
is _01101001 01110011
a _01100001
test _01110100 01100101 01110011 01110100
---------

The concept that I overlooked was that I had to first convert it to Ascii, then to Binary.

Again, thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top