Hi john1000:
A single byte integer can store a range of 256 integer values.
Typically, the exact range represented is 0 through 255, or [0, 255].
The reason for this? A byte has 8 bits, or eight signals, each having
one of two values, either 0 or 1. Therefore, a byte can have:
2^8 = 256 different values.
Sometimes, single byte values are used to represent *signed* integers,
meaning the range [-128,127].
The following comes from a page about the computer language FORTRAN:
"The standard trick in FORTRAN for reading unsigned data is to read
each datum value into a signed integer of the same size and then copy
numbers into the next bigger size INTEGER or REAL. Most negative
numbers are stored as twos-complement these days so the conversion
consists of adding the appropriate offset. For byte data that would be
2^8 i.e. 256, for 2 byte data it's 2^16 i.e. 65536, and for 4 bytes
data it's 2^32 (whatever that is). If you know that none of the data
values are greater than half the largest possible value then no
conversion is necessary. For example the largest possible unsigned
byte value is 255. If you know that all of the data is less than or
equal to 127 then no conversion (other than ICHAR) is needed."
From: http://cires.colorado.edu/~knowlesk/programming/fortranio.html
There is an excellent little Powerpoint presentation on this that you
can view using your browser:
"Integer Types"
http://www.cis.upenn.edu/~matuszek/cit591/Slides/numbers.ppt
I hope this answers you question.
Thank you.
websearcher-ga |