We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, I'm using IAR Embedded Workbench ARM are: being int a; and unsigned char b = 0x03; a = ~ b; should not be 0xfc and not 0xfffffffc? Is this a bug or is it deliberate?
Hi,
as the results, the compiler is right.
Because the operations are performed with the type matching,
a = ~b;
is identical to
a = (int)~b; .
Also,
a = (int)~b;
means
if(~b[7]==1) a = {0xffffff, ~b[7:0]};
else a = {0x000000, ~b[7:0]}; .
If you want to put 0xfc into the variable a, you should write as the following.
a = (unsigned char)~b;
Best regards,
Yasuhiko Koumoto.