UncleJack
Programmer
- Sep 20, 2001
- 344
I need to read the first four bits of a byte. Anyone know a way using VBA to do this?
Uncle Jack
Uncle Jack
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Public Function basByteMask(BytIn As Byte, Mask As Byte) As Byte
'Michael Red 1/9/02
'As usual, for illustration ONLY.
'ByteIn is a BYTE (0-255)
'Mask is a BYTE (0-255)
'Returns a BYTE (0-255)
'Note: Values of BIts in the Byte:
' (Bit #8) = &H80 = 128 (MSB)
' (Bit #7) = &H40 = 64
' (Bit #6) = &H20 = 32
' (Bit #5) = &H10 = 16
' (Bit #4) = &H08 = 08
' (Bit #3) = &H04 = 04
' (Bit #2) = &H02 = 02
' (Bit #1) = &H01 = 01 (LSB)
' (Bit #7) = &H00 = 00 (Empty - Would ALWAYS Return 0)
basByteMask = BytIn And Mask
End Function