Tiny Function to unsign a byte from READBYTE value

Previous topic - Next topic

spicypixel

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 =)

http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Moebius

Nice - but look up READUBYTE in the docs  ;)
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

spicypixel

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
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Moebius

I only noticed because someone else posted about it a while ago  =D
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

Ian Price

I think we've all been caught out by that one in the past, especially us old Blitz users.
I came. I saw. I played.

Moru

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

spicypixel

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 =)
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.