Define the following variables. Assume that int occupies 2 bytes, long occupies 4 bytes, and char occupies 1 byte!
Int I = 0x1234; // occupies two bytes <br/> long l = 0x12345678; // occupies four bytes <br/> char C = 0x12; // occupies one byte
Why is the hexadecimal value of the int type four digits? Step by step!
First, what is the concept of converting int type to binary type?
1 int byte is converted to 8 binary bits, for example, int A = 100; then the binary form of A is 25 + 24 + 22; that is, 0011 0100;
Converting int type to binary type is 1 to 8!
Next, let's look at the conversion of binary and hexadecimal:
You probably guessed it. Yes, that's right! Four Binary values are converted to one hexadecimal value. The values are: 0011 0100 ---> 0x34.
Therefore, the conversion between decimal and hexadecimal is like this. One byte is changed to two digits, and the two byte is changed to four digits...
Therefore, defined as long l = 0x12345678 actually occupies 8/2 = 4 bytes!
Postscript: It's all about university skipping classes !!!