Bit analysing

How do I take a number and check the bits of it. Here is an example of what I mean.

x = 16894

What would 16894 equal to...bit wise. Thanks in advance.

Comments

  • : How do I take a number and check the bits of it. Here is an example of what I mean.
    :
    : x = 16894
    :
    : What would 16894 equal to...bit wise. Thanks in advance.
    :
    [code]
    If ([italic]Number[/italic] And (2 ^ [italic]BitNum[/italic])) = (2 ^ [italic]BitNum[/italic]) Then
    [blue]'Bit is on[/blue]
    Else
    [blue]'Bit is off[/blue]
    End If
    [/code]

    To find out if bit 3 is turned on in the number 11:

    If (11 And 8) = 8 Then

    The MSb (most significant bit) needs to be handled differently in VB than in some other languages. For bytes, do the same as above. For Integers, Longs, etc. (numbers that support negatives) the topmost bit needs to be checked by seeing if the number is positive (off) or negative (on).
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion