Advanced programming of C language--binary algorithm and bit counting symbol

Source: Internet
Author: User
Tags bitwise

Language is not official;

Data storage operation is binary, binary number has the original code anti-code complement three kinds. Generally speaking binary is the original code. (Language not official)

Original code: 4 of the original code can be: 0000 0100; The highest bit 0 can be the number of symbols

Anti-code: Positive and original code is the same, negative sign bit unchanged, the remaining bit 0 change to 0

Complement: Positive and original code is the same, the complement of negative numbers on the basis of anti-code plus 1 (binary storage is a complement to save)

Binary octal in each other

Two-turn eight: three-bit turn one, eight turn two: a turn three bit;

binary decimal with mutual transfer

Two-turn 10: by 8 4 2 1 times the number of positions; ten to two: integer partial exhaustion 2 Take remainder method, fractional part multiplication 2 rounding method

Binary hexadecimal Mutual transfer

Two-turn 16: Four-bit turn one; 16 turn two: one turns four bits;

octal decimal with reciprocal transfer

Eight ext. 10: Same as the two-turn 10 principle, ten ext. Eight: Same as 10 ext. Two principle

octal hexadecimal Mutual transfer

The binary is the intermediate amount of cross-transfer.

Decimal hexadecimal cross-transfer

Ten ext. 16: Divided by 16, 16 ext. 10: Multiplied by 16 rounding

Data type

The six keywords short, int, long, char, float, double represent the six basic data types in C language.

Type conversions

&: Both the bitwise and the operation are 1 results to 1

|: bit or operation as long as the side is 1, the result is 1.

^: Bitwise XOR OR operation the same result is 0, the difference is 1

~: Bitwise NEGATION 0 Variable 0

<<: Left shift operation

>>: Right shift operation

In the C language for unsigned numbers, left to the right to 0, the right to move the operation to the left of 0, for the number of symbols, left to the right to fill 0, the right to move the left side of the operation of the sign bit, in the embedded, the specified shift is unsigned (unsigned).

Above are knowledge points, have the basis to understand!

In the C language, it is important to calculate more.

Advanced programming of C language--binary algorithm and bit counting symbol

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.