What is the size of integer in 8-bit, 16-bit, 32-bit processors/microcontrollers ? I guess it depends on the internal accumulator/register size. But not sure. Thanks
I'm only aware of one programming language that defines an integer
data type, but it's seldom used for 8 and 16-bit architectures. C is the most widely used language for programming 8-bit, 16-bit, and 32-bit architectures, so I assume you are looking for an answer in the context of C.
There are several "integer" data types in C: char
, short
, int
, long
, etc..., but I will assume what you really mean is the int
data type.
The size of an int
is not defined by the architecture, it is defined by the the C programming language specification, and it's extremely vague.
A ‘‘plain’’
int
object has the natural size suggested by the architecture of the execution environment (large enough to contain any value in the rangeINT_MIN
toINT_MAX
as defined in the header<limits.h>
).
I interpret this to mean it is determined by the implementation of the compiler.
You can find the latest publicly available version of the C11 standard (at the time of writing this answer) here: http://www.open-std.org/jtc1/sc22/wg14/www/standards.html.
Here are some tests I ran to help answer this question:
sizeof(int)
returns 2 (e.g. 16-bits) when compiled with GCC 4.3.2 (WinAVR 20081205)sizeof(int)
returns 4 (e.g. 32-bits) when compiled with GCC 4.9.2.sizeof(int)
returns 4 (e.g. 32-bits) regardless of whether it is compiled for 32-bit or 64-bit. Tested with both Visual Studio 2013 and GCC 4.9.2.A more interesting answer would be why those values were chosen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With