Share your advanced PureBasic knowledge/code with the community.
-
Droopy
- Enthusiast

- Posts: 658
- Joined: Thu Sep 16, 2004 9:50 pm
- Location: France
-
Contact:
Post
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
-
Pupil
- Enthusiast

- Posts: 715
- Joined: Fri Apr 25, 2003 3:56 pm
Post
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!
-
Droopy
- Enthusiast

- Posts: 658
- Joined: Thu Sep 16, 2004 9:50 pm
- Location: France
-
Contact:
Post
by Droopy »
Thanks I found this Fred code in the Us Forum this morning
Thanks

-
traumatic
- PureBasic Expert

- Posts: 1661
- Joined: Sun Apr 27, 2003 4:41 pm
- Location: Germany
-
Contact:
Post
by traumatic »
Droopy wrote:...in the Us Forum...
Where?
Good programmers don't comment their code. It was hard to write, should be hard to read.
-
Droopy
- Enthusiast

- Posts: 658
- Joined: Thu Sep 16, 2004 9:50 pm
- Location: France
-
Contact:
Post
by Droopy »
-
traumatic
- PureBasic Expert

- Posts: 1661
- Joined: Sun Apr 27, 2003 4:41 pm
- Location: Germany
-
Contact:
Post
by traumatic »
Thanks Droopy, I just wondered what the US-forums were

Good programmers don't comment their code. It was hard to write, should be hard to read.