C Language---Binary

Source: Internet
Author: User
Tags binary to decimal

1. What is a binary

Rounding mechanism, every few into one. The number of values in a position is a few steps in the operation.

In-Life: Decimal, 12 binary (12 months is 1 years), six decimal (60 seconds is 1 minutes)

In computer programming: binary, octal, 16 decimal, Binary

2. The role of the binary

Use a finite number to represent all values.

In decimal, for example, use 0~9 numbers to represent all values.

For example:

(1) Value 9: Use the number 9 to indicate

(2) Value 10: Use numbers 1 and 0 to denote

3, the rules of the system

(1) n binary uses numbers between 0~n-1 to represent all values

1) Binary 0 1

2) octal 0 1 2 3 4 5 6 7

3) Decimal 0 1 2 3 4 5 6 7 8 9

4) Hex 0 1 2 3 4 5 6 7 8 9 A B C D E F (a~f i.e. 10~15)

(2) n the value of the binary, each in the calculation is every n into a

1) in decimal when a value of 10 o'clock is indicated, the rule of decimal is required on the 9+1, and therefore 10 is used to represent the value 10

2) binary when a value of 2 o'clock is required, the binary rule is every binary one, so use 10 to represent the value 2

4. Binary conversion

(1) Concept

1) cardinality n is the cardinality of N, for example: the base of the decimal is 10

2) bit to the value of each bit of the description, right-to-left is the lowest bit, the highest bit, the lowest bit using 0, in order to increase the high direction

For example: a bit of 123 3 is the bit of 0,2 is the bit of 2

3) The right to n is N, for example: the right of the decimal is 10

4) the unit value corresponding to each position n^ (i-1)

(2) Decimal turn n binary

To even remove the rewind remainder

(3) n binary to Decimal

Sum by bit

5. Differentiate into system

(1) Decimal: No modification

(2) Octal: value before plus 0,0111

(3) 16 binary: value before plus 0x,0x111

(4) Binary: value before plus 0b,0b111

6. Knowledge of the system

(1) Decimal: For developers, binary: The computer can recognize the language, that is, 0, 1 encoding

(2) 1 x 16 binary bits = 4 bits hex: 0~f binary: 0000~1111 16 binary exists, more useful for the convenience of binary representation

Practice

Exercise 1. Calculates the value of decimal 42 converted to binary, octal, hexadecimal, respectively.

Decimal: 42;

Binary: 42/2=21 more than 0;

21/2=10 more than 1;

10/2=5 more than 0;

5/2=2 more than 1;

2/2=1 more than 0;

1/2=0 more than 1;

101010

Octal: 42/8=5 more than 2;

5/8=0 more than 5;

52

Hex: 42/16=2 more than 10;

2/16=0 more than 2;

2 A

Exercise 2. (*) calculates the decimal value corresponding to the binary 11010110.

Binary: 11010110;

Decimal: 0*2^0+1*2^1+1*2^2+0*2^3+1*2^4+0*2^5+1*2^6+1*2^7=214

Exercise 3. (*) calculates the decimal value corresponding to the octal 075.

Octal: 075;

Decimal: 5*8^0+7*8^1=61

Exercise 4. (*) calculates the decimal value corresponding to the hexadecimal 0xa8.

Hex: 0xa8;

Decimal: 8*16^0+10*16^1=168

C Language---Binary

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.