A
Alf P. Steinbach
* Frederick Gotham:
It's just academic, but yes. §5.8/2 defines the result of << as a
bit-level operation, and as a value only for unsigned types. §5.8/3
defines the result of >> as a bit-level operation and as a value both
for signed and unsigned types (the latter only for non-negative values).
The cases excluded from these definitions are, AFAICT, exactly those
where the definitions would otherwise be incompatible with grey-code...
Alf P. Steinbach posted:
I was under the assumption that C++ had to store positive values as
follows:
0: 0000
1: 0001
2: 0010
3: 0011
4: 0100
5: 0101
6: 0110
7: 0111
8: 1000
9: 1001
10: 1010
11: 1011
12: 1100
13: 1101
14: 1110
15: 1111
Are you saying that:
(A) The machine could use another method such as "Gray code".
and
(B) My code could break on other systems, and thus isn't trully
portable?
It's just academic, but yes. §5.8/2 defines the result of << as a
bit-level operation, and as a value only for unsigned types. §5.8/3
defines the result of >> as a bit-level operation and as a value both
for signed and unsigned types (the latter only for non-negative values).
The cases excluded from these definitions are, AFAICT, exactly those
where the definitions would otherwise be incompatible with grey-code...