gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > integer format

#26616 - mlequim - Tue Sep 21, 2004 10:56 am

Hi ! How can I code manualy an integer on two bytes ?
I don't know the format for signed and unsigned int.

In fact i am creating an array of bytes from an editor in Java, and I want to create integer in this array of bytes to be accessed later by my program in C.

#26618 - keldon - Tue Sep 21, 2004 11:18 am

Byte 0 = the low byte of the integer, Byte 1 = the high byte of the integer

For an unsigned integer it is represented the same as an integer, but when a number is negative e.g. negative 10; the result is (65536 - 10) in 16 bit. Or you could simply have it as 0 - n and a signed negative will be produced.

All negative numbers have the highest bit set.

#26622 - mlequim - Tue Sep 21, 2004 12:46 pm

thanks for all :p

#26628 - Krakken - Tue Sep 21, 2004 2:36 pm

An integer on the GBA uses 4 bytes. For a 2 byte integer you need to use "short".

#26633 - ecurtz - Tue Sep 21, 2004 5:28 pm

Be careful using byte data you've generated in Java. Sun, in their infinite wisdom, has decided that nobody needs any unsigned data types. Unless you're going to be constantly recompiling you should probably just use the Java to generate a .c source file containing the arrays you want.

#26661 - mlequim - Wed Sep 22, 2004 12:02 pm

krakken> thanks krakken :D

ecurts> yes, that's what i am doing, I am creating an array of bytes in a .h file