These are chat archives for Fortran-FOSS-Programmers/General-Discussion

29th
Mar 2018
Izaak "Zaak" Beekman
@zbeekman
Mar 29 2018 13:01
@boorishpea that sounds like a c question, not a Fortran one. But, with twos complement integer arithmetic signed and unsigned integers behave the same way in terms of many but level operations. (I.e. wrap around on overflow, etc.) It is primarily the interpretation of the bit patterns (having a sign bit or not) that distinguishes them. Both can represent the same total number of distinct integers for the same word length. If a signed integer can represent the range (-N, N] then an unsigned integer of the same length can represent [0, 2N). (These ranges likely have some off-by-one errors, I can’t be bothered to look at/workout the exact information.) Unfortunately Fortran has no out of the box support for unsigned integers. So you use unsigned integers when you don’t need negative integers and want to represent larger ones with the same number of bits.