Current location - Music Encyclopedia - Chinese History - C language type conversion operation problem
C language type conversion operation problem
This question is a bit troublesome.

That's true.

Although you declared that you didn't sign it? Charles? a、b、c、d、e;

But in fact, when performing+-*/four arithmetic operations, he actually regards it as an integer variable int.

See a=0 first? There's nothing wrong with that.

B=25 1, 0000 if it is of int type? 0000? 1 1 1 1? 10 1 1 (32 in total, I only write these)

But because b didn't sign it? Char type, so each binary bit of b is111? 10 1 1

Well, here's the point.

A-b==-25 1 has now become an int type, which is the binary representation (complement) of -25 1 in the computer.

25 1? :0000? 0000? 0000? 0000? 0000? 0000? 1 1 1 1? 10 1 1

The complement of 25 1:111? 1 1 1 1? 1 1 1 1? 1 1 1 1? 1 1 1 1? 1 1 1 1? 0000? 0 100 plus 1: means -25 1.

1 1 1 1? 1 1 1 1? 1 1 1 1? 1 1 1 1? 1 1 1 1? 1 1 1 1? 0000? 0 10 1

This is the representation of -25 1 in memory.

good

At this time, this value is assigned to d, so only the lowest 8-digit number 0000 is left. 0 10 1, another unsigned number. Look, it's already 5 o'clock.

So the value of d is finally 5.

Here C=(a-b)/4

-25 1/4==-62 (integer)

-62 said in the computer:

62:? 0000? 0000? 0000? 0000? 0000? 0000? 00 1 1? 1 1 10

anticode plus 1: 1 1 1 1? 1 1 1 1? 1 1 1 1? 1 1 1 1? 1 1 1 1? 1 1 1 1? 1 100? 000 1+ 1

? 1 1 1 1? 1 1 1 1? 1 1 1 1? 1 1 1 1? 1 1 1 1? 1 1 1 1? 1 100? 00 10

Take the lowest 8 bits to assign a value to c:

c? : 1 100? 00 10

Because c is unsigned? Charles? Most significant bit is not a sign bit, but is 194 when converted into an integer.

So finally c is 194 and d is 5.