Computer Basics: decimal/hexadecimal/binary

Source: Internet
Author: User

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 !!!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.