Help with Bit Manipulation - Programmers Heaven

#### Howdy, Stranger!

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

#### Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# Help with Bit Manipulation

Posts: 3Member
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.

• Posts: 2,444Member
: 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

• Posts: 3Member
: : 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