January 24, 2021, 12:52:06 PM

Author Topic: [bmx] Signed Byte & Short Functions by N [ 1+ years ago ]  (Read 707 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] Signed Byte & Short Functions by N [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : Signed Byte & Short Functions
Author : N
Posted : 1+ years ago

Description : 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).


Code :
Code: BlitzMax
  1. ' Signed Short -> Int
  2. Function ShortInt%( s@@ )
  3.     Return (s Shl 16) Sar 16
  4. End Function
  5.  
  6. ' Int -> Signed Short
  7. Function IntShort@@( i% )
  8.     Return ((i&$80000000) Shr 16)|(i&$7FFFFFFF)
  9. End Function
  10.  
  11. ' Signed Byte -> Int
  12. Function ByteInt%( s@ )
  13.     Return (s Shl 24) Sar 24
  14. End Function
  15.  
  16. ' Int -> Signed Byte
  17. Function IntByte@@( i% )
  18.     Return ((i&$80000000) Shr 24)|(i&$7FFFFFFF)
  19. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal