Re: Code problem
jacob navia wrote:
Yes, that's the error. Conversion from one type to another
involves the *value* being converted, not its representation.
As a related example consider
signed char sc = -1;
int a = sc;
unsigned int b = sc;
In neither case will "reinterpre t the bits and then convert"
produce the correct answer. What you're doing is more akin to
unsigned int c = (unsigned char)sc;
--
Eric Sosman
esosman@ieee-dot-org.invalid
jacob navia wrote:
[...]
But the abstract problem is still not clear to me. I mean when I see
a number like
>
-3
>
unadorned this is a signed integer constant. Since I am assigning it to
an unsigned value, I reinterpret the bits as an unsigned (this is my
mistake probably) and then convert THAT into an unsigned long long.
But the abstract problem is still not clear to me. I mean when I see
a number like
>
-3
>
unadorned this is a signed integer constant. Since I am assigning it to
an unsigned value, I reinterpret the bits as an unsigned (this is my
mistake probably) and then convert THAT into an unsigned long long.
involves the *value* being converted, not its representation.
As a related example consider
signed char sc = -1;
int a = sc;
unsigned int b = sc;
In neither case will "reinterpre t the bits and then convert"
produce the correct answer. What you're doing is more akin to
unsigned int c = (unsigned char)sc;
--
Eric Sosman
esosman@ieee-dot-org.invalid
Comment