0

I want to add 0x9E3779B9 and 0xB7E15163 inside a 32-bit variable but it is overflowing because the result, 0x15618CB1C, is 36 bit . I want the result to be 0x5618CB1C, it works fine in c++ but not in Visual Basic.

I tried to combine Uint32 and int32 variables in Visual Basic and it's working somehow:

 Dim Q As UInt32
 Dim R As Int32
 Q = &H9E3779B9UI
 R = &HB7E15163 
 R + Q

But is there any way to add those with one type variable only?

meh96
  • 1
  • 3
  • 1
    I'm quite sure this as nothing to do with vba... maybe you meant vb.net? – Vincent G Sep 05 '17 at 06:47
  • I thought it was the same, i deleted vba tag – meh96 Sep 05 '17 at 08:22
  • Whether that code generates an overflow exception is a project setting. You can change it from Project > Properties > Build tab to make vb.net behave like C++. It is however a global setting, so not a great idea. Using different types forces the compiler to look for another type that is compatible with both UInt32 and Int32. That will be Long, no more overflow. Consider just getting it over with by declaring both values as Long. If you want to hammer that back into a 32-bit Integer then consider [this approach](https://stackoverflow.com/a/4656890/17034). – Hans Passant Sep 05 '17 at 09:16

0 Answers0