Page 1 of 1

Signed Binary annoying ?

Posted: Sat May 21, 2005 10:40 pm
by Droopy
Code updated For 5.20+

Convert signed binary to unsigned binary ( as long )

Code: Select all

Procedure SignedBinaryToUnsigned(Byte.b)
  If Byte & %10000000 
    Byte=Byte & %01111111
    Retour=Byte+128
  Else
    Retour=Byte
  EndIf
  ProcedureReturn Retour
EndProcedure
and for testing

Code: Select all

;/                                     Unsigned   Signed
Debug SignedBinaryToUnsigned(%00000000) ; 0         0
Debug SignedBinaryToUnsigned(%01111111) ; 127       127
Debug SignedBinaryToUnsigned(%10000000) ; 128       -128
Debug SignedBinaryToUnsigned(%11111111) ; 255       -1

Re: Signed Binary annoying ?

Posted: Sun May 22, 2005 12:00 am
by Pupil
Droopy wrote:Convert signed binary to unsigned binary ( as long )

Code: Select all

Procedure SignedBinaryToUnsigned(Byte.b)
  If Byte & %10000000 
    Byte=Byte & %01111111
    Retour=Byte+128
  Else
    Retour=Byte
  EndIf
  ProcedureReturn Retour
EndProcedure
and for testing

Code: Select all

;/                                     Unsigned   Signed
Debug SignedBinaryToUnsigned(%00000000) ; 0         0
Debug SignedBinaryToUnsigned(%01111111) ; 127       127
Debug SignedBinaryToUnsigned(%10000000) ; 128       -128
Debug SignedBinaryToUnsigned(%11111111) ; 255       -1
Why not use this?...

Code: Select all

Procedure SignedBinaryToUnsigned(byte.b)
  ProcedureReturn byte & $ff
EndProcedure
... or just using this 'MyByteVar & $ff' inline instead!

Posted: Sun May 22, 2005 7:18 am
by Droopy
Thanks I found this Fred code in the Us Forum this morning

Thanks :D

Posted: Sun May 22, 2005 11:56 am
by traumatic
Droopy wrote:...in the Us Forum...
Where?

Posted: Sun May 22, 2005 12:55 pm
by Droopy

Posted: Sun May 22, 2005 1:02 pm
by traumatic
Thanks Droopy, I just wondered what the US-forums were ;)