Number System and Its Conversion

Source: Internet
Author: User
Tags decimal to binary

N-Base

Broadly speaking, N-base can be said to be any base. In reality, 0 and 1 are meaningless, so N 2 is a positive integer. There are two purposes for which N-base is introduced. The first is to use N-base to combine the Conversion Relationship Between decimal and other hexadecimal systems; the second is to promote the Conversion Relationship between hexadecimal systems to any hexadecimal system.

(1) mutual conversion between decimal and N-Base

To promote the Conversion Relationship Between decimal and binary to other hexadecimal systems, we can draw the following conclusions:

① Binarization ten, polynomial; ten to two, integers in addition to 2 take the remainder, decimal number multiplied by 2 take the integer.

② Sanhua ten, polynomial; Shihua three, integers in addition to 3 get the remainder, decimal multiply 3 get the integer.

③ Four to ten, polynomial; four to ten, integers in addition to 4 to take the remainder, decimal number multiplied by 4 to take the integer.

④ Ten to ten, polynomial; eight to ten, integers except 8 to take the remainder, decimal number multiplied by 8 to take the integer.

......

It can be summarized:

"N to ten, polynomial; n to ten, integers except n to take remainder, decimals multiplied by N to take an integer ."

(2) conversion rules between any hexadecimal order

The conversion between any hexadecimal system refers to the conversion between the three-hexadecimal System and the five-hexadecimal system, the six-hexadecimal system, and the nine-hexadecimal system. According to the conversion rules of decimal and N-base, the conversion between any decimal systems can be based on the decimal system to establish the Conversion Relationship between any decimal systems, the conversion relationship is called "n → 10, 10 → N ". For example, convert the three-in-one number to the decimal number, and then convert the decimal number to the five-in-one number.

When the weights of the two hexadecimal systems are full power times, such as binary and octal, binary and hexadecimal, you can use the "fight and split" rule to convert the two hexadecimal notation.

With the concept of N-base, you can define a base system as needed, or convert the information in one base system to the data in another base system, for the convenience of exchange or information confidentiality. For example, 26 English letters can be defined as '26' or '27', and the Chinese zodiac is defined as '12' or '13.

Difficulties

To understand binary, octal, hexadecimal, or any other hexadecimal, first we can start with the most familiar decimal system, analyze and master the characteristics of the decimal system, and promote it to other hexadecimal systems, create a binary, octal, and hexadecimal conversion method. Then, starting from the commonalities of the carry notation system, we can find out how to convert decimal to binary, octal, and hexadecimal. In addition, by analyzing binary, octal, and hexadecimal systems, we can conclude that there is a "kinship" Relationship Between Binary Systems and octal and hexadecimal systems. Understanding and understanding the analysis methods of the above three problems will naturally lead to several easy-to-remember rules for the conversion of the notation system.

Rule 1Binarization ten, polynomial. That is, to convert the binary number (or octal number, hexadecimal number, and any hexadecimal number) into a decimal number, you can expand the number into a polynomial, and then use decimal to calculate the polynomial, to complete the conversion.

Rule 2Decimal two, integers except 2 get the remainder; decimals multiply by 2 get the integer. If a decimal integer is converted to a binary number, the integer can be removed with 2 each time until the business is zero and the remainder is sorted in sequence, it is the binary number corresponding to a decimal INTEGER (the remainder is sorted from the back to the Front ). If the decimal number is a decimal number, you can use 2 to multiply the number one by one, and sort the integers obtained by each multiplication in sequence, it is the binary number corresponding to the decimal place (the integers are arranged in decimal order ).

It is worth noting that some decimal places may not be converted, as the decimal part will not always be 0. For example, the decimal values of 0.1 and 0.6 are not balanced. When there are endless things, the approximate values are generally obtained according to requirements. For example, take an approximate value based on given positioning, or take an approximate value based on a given number of digits.

Rule 3Merge the three parts into one, and split them into three parts. That is, the three bits of the binary number are combined into one bits, and the one of the bits is split into three bits of the binary number.

Rule 4Erhua 16th, where the four members join each other. The two are split into four parts. That is, the four digits of the binary number are combined into one digit of the hexadecimal number, and the one digit of the hexadecimal number is split into four digits of the binary number.

1) N-base definition

N-base is a type with 0 ~ N-1, a total of N base numbers, each n into the right to count. Any arrangement of base numbers, plus positive, negative, decimal point can constitute an integer, negative, integer, decimal.

Obviously, when n = 2, it is binary; when n = 8, it is octal; when n = 10, it is decimal; when n = 16, it is hexadecimal; when n = 24, it is twenty-four hexadecimal, and so on.

2) polynomial representation of n-base numbers

The order is a weight coefficient, which is a weight. The N-base number can be expressed as a polynomial of the sum of the weight coefficient and the bit weight product:

(M, n are positive integers)

Obviously, when n = 2, the value ranges from 0 ~ 1, =, the above formula is the polynomial of the binary number; when n = 10, the value is 0 ~ 9, =, the above formula is the polynomial representation of the decimal number. And so on, the polynomial representation of any hexadecimal number can be obtained. Therefore, if you understand the n-base, you will understand any base.

3) Conversion of N-base numbers

(1) Conversion of hexadecimal Systems

You can also perform things in octal mode, that is, you can perform things in octal mode and then perform the things in octal mode. The decimal sixteen can also be performed using binary, that is, the decimal two and the decimal sixteen. In short, in mutual conversion, binary, octal, and hexadecimal systems can be considered as three different manifestations of the same hexadecimal System for decimal conversion.

(2) Arbitrary hexadecimal conversion

When N is an integer power of 2, for example, N equals ,,,,..., The Conversion Relationship Between the n-base and binary is a split and fight relationship. For example, the relationship between the bytes and binary is "one split into five, five digits and one fight.

When N is neither 10 nor an integer power of 2 or 2, for example, n is equal to 3, 5, 6, 7, 9, how can we convert the n-hexadecimal notation? For example, the conversion between three-in and five-in, six-in and seven-in, and nine-in and twelve-hour. In this case, the conversion party can be converted to decimal, and then the Conversion Relationship between 10 and N is formed.

References:

[1] Liu kewu. Software Designer Examination Subject 1: computer and software engineering knowledge-test site analysis and simulation training [M]. Beijing: Tsinghua University Press, 2005.1.

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.