19 February 2019, 11:40 | #1 |
Registered User
Join Date: Oct 2008
Location: Finland
Posts: 643
|
Unsigned bytes
Is it possible to have a byte (.b) be handled as unsigned rather than signed?
I'm reading a tilemap as a binary file with one byte representing one tile. The values in the tilemap are unsigned (0-255). I read the tilemap into a byte array in Blitz Basic and the values become signed when reading from the array (all values after 128 become negative). Can I overcome this without using a word (.w) array? |
19 February 2019, 13:13 | #2 |
Registered User
Join Date: Oct 2008
Location: Finland
Posts: 643
|
I just figured out one way to do it. If you look at the example:
Code:
; Byte variables in BB2 are signed ( -127..128) ; So let's set the value of a byte variable to 200 variable.b=200 ; If we now read the variable it will have a value of -56, since values above 128 are negative for a signed byte. Print variable ; -56 is printed, which is NOT what we want ; If we use bitwise AND on the variable with 255 (%11111111), we get the correct value Print (variable & 255) ; 200 is printed, which IS what we want Last edited by MickGyver; 20 February 2019 at 17:23. |
20 February 2019, 21:53 | #3 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
|
Yeah, all variables are signed in Blitz unfortunately. The simplest way around it would be to use a Word array, with the obvious downside of doubled memory usage. It shouldn't significantly slow things down however, given the 16-bit bus on even the lowest of Amigas.
|
21 February 2019, 11:44 | #4 | |
Registered User
Join Date: Oct 2008
Location: Finland
Posts: 643
|
Quote:
|
|
21 February 2019, 16:09 | #5 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
|
Probably not. If the compiler was clever and saw that you were loading multiple 8-bit values from adjacent locations (such as a string or an array), it might be able to load two at once, but I don't think the Blitz compiler is all that smart when you're dealing with each value separately. It would be an interesting benchmark to test, but I can't see there being any difference at all.
|
23 March 2019, 02:21 | #6 |
Registered User
Join Date: Sep 2007
Location: Stockholm
Posts: 4,332
|
You can turn off overflow errors in the compiler settings if you know what you're doing.
|
23 March 2021, 18:49 | #7 |
Registered User
Join Date: May 2001
Location: ?
Posts: 19,645
|
Well hellooooo, it's me going nuts again over some undecipherable bug, and it turns out, it's Blitz pulling the rug from under my feet again and not me doing something wrong
This "all variables are signed" shit is mental. Now I need to do this with a Word variable which was throwing negative values after 65KB Thanks MickGyver and Daedalus for the light thrown on this. |
10 April 2021, 21:00 | #8 |
Banana
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,213
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to get free bytes on volume? | AGS | Coders. System | 12 | 02 March 2016 16:58 |
Elysium by Magic Bytes | CodyJarrett | request.Old Rare Games | 41 | 28 December 2011 18:33 |
WallStreet - Magic bytes | dlfrsilver | HOL contributions | 0 | 20 September 2008 23:37 |
0 bytes ADF Files | Bueller | support.WinUAE | 2 | 30 September 2005 13:50 |
|
|