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.

DS development > Q: Integer Definitions

#60668 - GrenadeJumper - Sun Nov 13, 2005 4:16 pm

Hi All,

Can anyone explain to me the basic differences between int, uint8, uint16, and any other integer definitions I don't know? I'm starting a project, and it struck me that I don't actually know :)

Thanks,
<! GrenadeJumper !>
_________________
H/W: European NTR-001 - natrium42 PassMe v1.4 - Extreme Flash Advance 256Mb
S/W: EFA-Linker 2.5 - PA_Lib - Programmer's Notepad 2

#60676 - Mighty Max - Sun Nov 13, 2005 5:33 pm

its [u]int[8|16|32...]

defining 8,16 or 32 bit [un]signed ordinal values.

int without the bitsize specification uses the machine's word size. For arm this should be 32bit.

The range for signed is
-(2^(bits-1)) till +(2^(bits-1))-1

The range for unsigned is
0 till (2^bits)-1


(^ is to the power of, not xor in this case)
_________________
GBAMP Multiboot

#60678 - LOst? - Sun Nov 13, 2005 5:39 pm

The number 8 to 32 explains how many bits are used. A byte contains 8 bits. A word contains 16 bits. A double word contains 32 bits.

The unsigned part uses the whole bit range as positive numbers. For a byte that would be 0 to 255.

A signed byte uses half the values for negative values. The most significiant bit is the negative sign making the values 128 to 255 the nagative range -128 to -1.
_________________
Exceptions are fun

#60694 - GrenadeJumper - Sun Nov 13, 2005 11:30 pm

Thanks guys, clears it up for me :)
_________________
H/W: European NTR-001 - natrium42 PassMe v1.4 - Extreme Flash Advance 256Mb
S/W: EFA-Linker 2.5 - PA_Lib - Programmer's Notepad 2