Manipulating bits

S

Sunny

I have two questions:

1) How do you separately read the bits in a byte/word?
For example, I want to read the two MSB's of a word, each
into a separate variable. How do I do this?

2) Is there a way to actually write out a number in
binary in VB? For example, instead of saying X = 8, can
you write it in binary as X = 00001000? If so, what is
format you have to write it in?

Thanks.

Sunny
 
B

Bernie Deitrick

Sunny,

Set a reference to ATPVBAEN.xls, then use something like:

Sub test()
Dim i As Integer

For i = 0 To 2 ^ 8
MsgBox "The number " & i & " in Binary is " _
& Dec2Bin(i, 8) & Chr(10) & _
"And it's MSB is " & Left(Dec2Bin(i, 8), 1) & Chr(10) & _
"And it's 2nd MSB is " & Mid(Dec2Bin(i, 8), 2, 1)

Next i

End Sub

HTH,
Bernie
MS Excel MVP
 
Top