Understanding of data transformations

Source: Internet
Author: User

When different types of data are converted, the low-level is copied to the object,

For example, long to int is the lower 32 bits to int, so that if the high 32 bits have data, then the data of that part is lost.

If int to long, it is int 32 bit to long of low 32 bits, high 0, such as int is negative, then high 32 is the highest bit 1, the remaining complement 0;

after a long is converted to int, is the data in int a long 32-bit or a low 32-bit?

So, int to unsigned int is to give the 32 bits of int directly to unsigned int.

In other words, give the bit to each other.

As for the output of what results, there is a system more type judgment.

Instance:

The binary representation method of the int-1 is 11111111111111111111111111111111, because it is of type int, so the system will be judged as-1;

The binary representation of unsigned int 4294967295 is also 11111111111111111111111111111111, because it is the unsigned int type, so the system will be judged to be 4294967295;

Conclusion:

In the final analysis, the data type behaves as binary at the bottom. For example, int has 32 bit, and long has 64 bit.

When it comes to Java and C type conversions, the number of bits in the data type is a concern.

You can match Java's uint8_t of Byte and C; (typedef unsigned char uint8_t).

Although the Java byte is signed, and the uint8_t is unsigned, but there is no relationship, the second binary notation is the same, it is necessary to note that when parsing the data, know that there is a difference, the attention point, there is no problem.

Understanding of data transformations

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.