Blitz (68/176)

From:David McMinn
Date:20 Jul 2001 at 18:39:03
Subject:Re: Unsigned Byte tables

On 19 Jul 2001, at 9:23, Richard Brooklyn wrote:

> What is an unsigned byte table?

An array of unsigned bytes I guess. You do know how binary -> decmal
conversion works? OK, in case you don't, in a byte each bit has a weight.
As you look at the binary number written normally, the weightings (for an
unsigned number) are this:

128 64 32 16 8 4 2 1

To convert from binary -> decimal, just add up all the weights where you
have a 1 in your binary number, so 11001101 would be 128+64+8+4+1=205.

However, Blitz always uses signed numbers (stored in two's complement
format). All this basically is that instead of the weight for the highest
bit being 128, it is -128. Same rules apply for conversion, but now you
can store numbers between -128 and +127 instead of 0 to 255.

> And how can I process them?

It depends what you want to do with them. I used to have a nice trick
with newtypes which let you access arrays as arrays via a pointer, but I
recently found it doesn't work properly with bytes :(

You'll probably need to Peek the memory locations. For example, you will
have the address of this table (say addr.l). To access a byte in the
table, you simply add the number of the byte you want to access (starting
from 0) multiplied by the size of each item in the table (in this case,
each item is a byte, which obviously has a size of 1 byte, so you don't
need to multiply here). After that, you need to convert it to the range 0
to 255.

For example, if you wanted to read the 5th item from the table (starts
from 0!) you could do something l;ike this:

; read byte from table
value.b = Peek.b(addr + 4)

; Store in word so we can access correct range
; We AND the value with $FF so that the value is not sign-extended to
; the size of a word, and gives us the value in the range 0 to 255.
realval.w = value & $FF

> Am I making any sense at all?

Nope ;)

|) /\ \/ ][ |) |\/| c |\/| ][ |\| |\| | dave@blitz-2000.co.uk
http://members.nbci.com/david_mcminn | ICQ=16827694

---------------------------------------------------------------------
To unsubscribe, e-mail: blitz-list-unsubscribe@netsoc.ucd.ie
For additional commands, e-mail: blitz-list-help@netsoc.ucd.ie