Help !

  • Thread starter Thread starter Gary
  • Start date Start date
G

Gary

Hi,

When ever i test the follwing the Overflow error -6 is occuring

sub test()

dim L as long

dim D as double

dim result as double

L=12112'any value

D=2^31

result= L and D

result= L or D

result= L or(not D)

end sub

It seems that the bitwise operator "or,Xor,And,Not" may not work on 32bit
number with signbit?

Please help !

Gary
 
Hi, this looks like VB5/6 Code, this is a VB.NET newsgroup, you'll have
better luck posting to one of the microsoft.public.vb.* groups

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations
 
Hi Gary,

Lol. This one is a puzzler for three reasons.
1 VB.NET doesn't give Overflow error -6 when it can give an
OverflowException.
2 Dim L As Long gives you a 64-bit value.
3 The code gives me no errors even if I change L to an Integer.

However, leaving that aside, 2^31 is indeed going into the sign bit for a
32-bit integer. Basic has <always> been terrible at supporting work involving
bits. <Always>. It's been a pain in the bum since the year dot. Grrr.

The workarounds have traditionally involved lots of Ifs and Elses.

For instance with the specific case of 2^31
If D = 2^31 Then _
I = -D

This is why, if you are serious about you bit and bytes, a language that
provides unsigned integers is better, or one that has integers bigger than the
quantities that you'll be working with.

In VB.NET you can do all your high-end 32-bit manipulation using Longs. In
C# you just need unisgned ints

Regards,
Fergus
 
* "Gary said:
When ever i test the follwing the Overflow error -6 is occuring

sub test()

dim L as long

dim D as double

dim result as double

L=12112'any value

D=2^31

result= L and D

result= L or D

result= L or(not D)

end sub

It seems that the bitwise operator "or,Xor,And,Not" may not work on 32bit
number with signbit?

If you are using VB6, you may want to turn to the VB Classic groups (microsoft.public.vb.*).
 
Back
Top