Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 17974
Number of posts: 55343

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Help with Bit Manipulation Posted by WayneKeet on 11 Oct 2005 at 12:19 AM
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.

Report
Re: Help with Bit Manipulation Posted by BitByBit_Thor on 11 Oct 2005 at 9:51 AM
: 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

Report
Re: Help with Bit Manipulation Posted by WayneKeet on 12 Oct 2005 at 4:22 AM
: : 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





 

Recent Jobs