C-language Signed and unsigned conversions

Source: Internet
Author: User

Unsigned number: there are no positive or negative points, and all bits are used to represent the number itself.

Signed number: the highest bit is used to denote the positive or negative of the number, the highest bit is 1 for negative numbers, and the highest bit is 0 to indicate positive numbers.

1 . Unsigned number ---> signed number

See if the highest bit of the unsigned number is 1,

If it is not 1 (0), then the signed number is directly equal to the unsigned number;

If the highest bit of the unsigned number is 1, the unsigned number is complementary and the number is the signed Number.

2 . Signed number ---> unsigned number

See if the highest bit of the signed number is 1,

If it is not 1 (0), the unsigned number is directly equal to the signed number;

If the highest bit of the signed number is 1, then the signed number is complementary, and the resulting number is the unsigned number.

Summarize:

The conversion between the signed number and the unsigned number depends on whether the highest bit of the number to be converted is 1.

If it is not 1, then the conversion result is the number to be converted Itself;

If 1, The conversion result is the complement of the converted number (considered negative).

C-language Signed and unsigned conversions

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.