Dim number Dim activeBits number = InputBox("Enter 16-bit number:") activeBits = "" For i = 15 To 0 Step -1 If (number And (2 ^ i)) <> 0 Then activeBits = activeBits & "bit" & (15 - i) & "," End If Next i If Len(activeBits) > 0 Then activeBits = Left(activeBits, Len(activeBits) - 2) MsgBox "Active bits are: " & activeBits Else MsgBox "No bits are set in this number." End If
I wrote this code to see which bits are set from a 16-bit number i.e. the Boolean fan input output value. The user enters the value and it is meant to display the list of set bits, if any. I am not sure why it won't compile. Is there something obvious that I am overlooking or not spotting? Any help is appreciated.
Best regards,
Wilson
In reply to Matt Stoner:
In reply to Matt Forbis:
In reply to Wilson Halligan: