GLBasic forum

Codesnippets => Code Snippets => Topic started by: spicypixel on 2011-May-08

Title: Tiny Function to unsign a byte from READBYTE value
Post by: spicypixel on 2011-May-08
I'd written a simple map editor in BlitzPlus which writes out my mapdata as Bytes and when I read it into GLB the values are in the range -127...+127 and I needed them in the range 0...255. Here is a quick and easy way to do that which although not rocket science does help keep your code looking cleaner.

Function Code
Code (glbasic) Select

// .------------------------------------.
// |  Unsign READBYTE value to 0...255  |
// `------------------------------------'
FUNCTION UnsignByte: value%
IF value% < 0 THEN value% = 256 + value%
RETURN value%
ENDFUNCTION


Usage
Code (glbasic) Select
signed_byte% = UnsignByte(signed_byte%)

Hope you find it useful =)

Title: Re: Tiny Function to unsign a byte from READBYTE value
Post by: Moebius on 2011-May-08
Nice - but look up READUBYTE in the docs  ;)
Title: Re: Tiny Function to unsign a byte from READBYTE value
Post by: spicypixel on 2011-May-08
Noob alert here lol. I guess it's still handy for poeple to see how it's converted even though maybe I should read the docs more next time =D
Title: Re: Tiny Function to unsign a byte from READBYTE value
Post by: Moebius on 2011-May-08
I only noticed because someone else posted about it a while ago  =D
Title: Re: Tiny Function to unsign a byte from READBYTE value
Post by: Ian Price on 2011-May-08
I think we've all been caught out by that one in the past, especially us old Blitz users.
Title: Re: Tiny Function to unsign a byte from READBYTE value
Post by: Moru on 2011-May-09
Yep, I'm the original one that got caught out with the problem of reading bytes from a file, Thanks Gernot for fixing it so fast back then :-)
Title: Re: Tiny Function to unsign a byte from READBYTE value
Post by: spicypixel on 2011-May-09
Quote from: Moru on 2011-May-09
Yep, I'm the original one that got caught out with the problem of reading bytes from a file, Thanks Gernot for fixing it so fast back then :-)

Hehe guess we won't be the first, OR the last lol =)