Hello all.
How do you properly express &H80000000 in PB?
Thank you
Tim
how to express a byte value?
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: how to express a byte value?
You could cast it to a type large enough to hold it without the sign affecting the result:
Or, if all you want to do is display the correct value, another option:
Code: Select all
num.q = $80000000
Debug num
Code: Select all
num.l = $80000000
Debug StrU(num, #PB_Long)
BERESHEIT
Re: how to express a byte value?
But I need to do some math with it.
I guess PB is not real strong on bit/byte manipulation? I need to work with these from time to time when dealing with external uC based units. Again, am real green on PB so probably just me....
Any ideas?
Thank you!
Tim
I guess PB is not real strong on bit/byte manipulation? I need to work with these from time to time when dealing with external uC based units. Again, am real green on PB so probably just me....
Any ideas?
Thank you!
Tim
Re: how to express a byte value?
These are the functions I am trying to port from VB6
Maybe there is a better way of doing this in PB that I am not aware of.
Tim
Code: Select all
Procedure.i LShiftLong(Value.i, Shift.w); As Long
Define ReturnValue.i
;Define Si.w
MakeOnBits()
If (Value & (2 | (31 - Shift))) :Goto OverFlow :EndIf
ReturnValue = ((Value & OnBits(31 - Shift)) * (2 | Shift))
ProcedureReturn ReturnValue
OverFlow:
;LShiftLong = ((Value And OnBits(31 - (Shift + 1))) * (2 ^ (Shift))) Or &H80000000
ReturnValue = ((Value & OnBits(31 - (Shift + 1))) * (2 ^ (Shift))) | &H80000000
ProcedureReturn ReturnValue
EndProcedure
Procedure.i RShiftLong( Value.i,Shift.i); As Long
Define ReturnValue.i
Define hi.i
MakeOnBits()
If Value & &H80000000
hi = &H40000000
EndIf
ReturnValue.i = (Value & &H7FFFFFFE) \ (2 | Shift)
ReturnValue.i = (RShiftLong | (hi \ (2 | (Shift - 1))))
ProcedureReturn ReturnValue.i
EndProcedure
Procedure MakeOnBits()
Define ReturnValue.i
Define j.i
Define v.i
For j = 0 To 30
v = v + (2 | j)
OnBits(j) = v
Next j
OnBits(j) = v + &H80000000
EndProcedure
Maybe there is a better way of doing this in PB that I am not aware of.
Tim
Re: how to express a byte value?
Any idea what the functions are supposed to do? That is the real key to porting them.tseyfarth wrote:These are the functions I am trying to port from VB6
Re: how to express a byte value?
tseyfarth wrote:Hello all.
How do you properly express &H80000000 in PB?
Thank you
Tim
$80000000 is not a byte value, it can't fit in a byte. But you can put it in a long, integer or quad variable.how to express a byte value?
Your functions are named lshift and rshift, I'm guessing they shift bits right and left. This is built-in in PB. Take a look in the help file for arithmetic shift left and right. If the functions happen to rotate rather than shift, you can easily do that with inline assembly.
Re: how to express a byte value?
Just a little add on to what Trond has said above about bitshifting. be careful when you are bitshifting with large numbers such as you have indicated with the mask value from your original post as PB does not have any unsigned long & potentially will give you a headache trying to work out where things go wrong when you shift a negative number to the right mainly. ( Just use a 64 bit type such as a quad instead to avoid this, which of course depends I guess on exactly what it is you are trying to achieve )
Code: Select all
a.l=$80000000
Debug a
Debug Bin(a)
a>>31
Debug a
Debug Bin(a)
b.q=$80000000
Debug b
Debug Bin(b)
b>>31
Debug b
Debug Bin(b)
Re: how to express a byte value?
I don't recall the purpose
But I do know that the numbers are always positive.
Will look for and try the bit shifting built in.
TY
Tim

Will look for and try the bit shifting built in.
TY
Tim