Code archives/Algorithms/Signed Byte & Short Functions
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
| These are functions that are used to convert signed shorts & bytes to integers (since converting them to a BMax short or byte is useless as they're unsigned) and vice versa (e.g, integer->signed short). These are especially useful when you want to save space in binary formats. Thanks to Floyd for help with this (about a year ago, no idea if anyone remembers but I figured I'd throw that in). | |||||
' Signed Short -> Int
Function ShortInt%( s@@ )
Return (s Shl 16) Sar 16
End Function
' Int -> Signed Short
Function IntShort@@( i% )
Return ((i&$80000000) Shr 16)|(i&$7FFFFFFF)
End Function
' Signed Byte -> Int
Function ByteInt%( s@ )
Return (s Shl 24) Sar 24
End Function
' Int -> Signed Byte
Function IntByte@@( i% )
Return ((i&$80000000) Shr 24)|(i&$7FFFFFFF)
End Function |
Comments
None.
Code Archives Forum