Help with Bit Manipulation

Hi all

I am new to VB programming and need some help.
I want to know if bit manipulation is possible in VB as in C++.

For example to see if a bit is a 1 or a 0 in a given word.
Also is there a function to convert a hex value to an int/float value.

Comments

  • : Hi all
    :
    : I am new to VB programming and need some help.
    : I want to know if bit manipulation is possible in VB as in C++.
    :
    : For example to see if a bit is a 1 or a 0 in a given word.
    : Also is there a function to convert a hex value to an int/float value.
    :
    :

    Integer = CInt("&H" & "67FF")
    Just prefix a hexidecimal sequence with &H and use a conversion function (like CInt).

    To check if a certain bit is set, you need to check by using powers of 2.

    For example, the first bit set is 2^0. The second bit set is 2^1.

    You can check any UNSIGNED number like this:
    If (Number And 2 ^ (BitNumber - 1)) Then
    MsgBox "Bit " & BitNumber & " is set (1)"
    End If

    You will, however, need to make an exception for the signed bits (since only the Byte is unsigned in VB).
    Basically, checking if a number is negative will return the sign bit.



    Greets...
    Richard

  • : : Hi all
    : :
    : : I am new to VB programming and need some help.
    : : I want to know if bit manipulation is possible in VB as in C++.
    : :
    : : For example to see if a bit is a 1 or a 0 in a given word.
    : : Also is there a function to convert a hex value to an int/float value.
    : :
    : :
    :
    : Integer = CInt("&H" & "67FF")
    : Just prefix a hexidecimal sequence with &H and use a conversion function (like CInt).
    :
    : To check if a certain bit is set, you need to check by using powers of 2.
    :
    : For example, the first bit set is 2^0. The second bit set is 2^1.
    :
    : You can check any UNSIGNED number like this:
    : If (Number And 2 ^ (BitNumber - 1)) Then
    : MsgBox "Bit " & BitNumber & " is set (1)"
    : End If
    :
    : You will, however, need to make an exception for the signed bits (since only the Byte is unsigned in VB).
    : Basically, checking if a number is negative will return the sign bit.
    :
    :
    :
    : Greets...
    : Richard
    :
    :
    Thanx Richard

    I entered your code and it worked fine.

    Again thank you.

    Regards
    Wayne


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