Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 139

Retreiving the value of each bit of a Long value

I am trying to interogate each bit of a Long value (32 bits). I use the following code to do so.

dim longValue as long
dim j as Integer
dim k as long

For j = 0 To 31
k = longValue And (2 ^ j))
k = IIf(k > 0, "1", "0")
rStr = rStr & k
Next j

msgbox rStr

When i get to 2^31 i get an overflow because this value is greater than that of a long.
Can anyone think of a beter way of finding the bit value of each bit in a long word. I am thinking of doing bitwise shifts to shift right the 32nd bit to avoid this.

Thanks
Bob

0
rkneal
1 Solution

IT Services ConsultantCommented:
Hi,

Try:

If j < 31 Then
k = longValue And (2 ^ j))
Else
k = &H80000000 Or longValue
End If

k = longValue And (2 ^ j))

Further routines in a previous thread here at E-E:

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_10122746.html

BFN,

fp.
0

Featured Post

Tackle projects and never again get stuck behind a technical roadblock.