Skip to main content

简要介绍进制和 ASCII 码表

· 4 min read

1. What is a Number System

  • Number System A number system, officially called "positional notation system", is a counting method. The most commonly used is the decimal system.
    • Decimal System The decimal system follows the "carry over at ten" rule, so it has 10 digits to represent numbers—0,1,2,3,4,5,6,7,8,9

In daily life, besides the decimal system, there are many other common number systems that you might not have noticed. For example, clocks use a base-60 system for seconds. The second hand goes from 0 to 59, then after one more second, it carries over to become one minute.

Speaking of computers, computers could also use the decimal system to represent numbers. So why do they specifically use binary? The reason is simple: binary only has 0 and 1, making it very simple to represent.

Why is binary simple? Because computers are fundamentally hardware, and choosing between two pathways versus ten pathways is definitely easier with the former. The only trade-off is that binary needs to take more steps to reach the same destination.

2. About Binary

Let's first look at how decimal numbers are represented. Suppose we have a decimal number (3107)10(3107)_{10}

Note

  1. Here the number (3107)10(3107)_{10} is enclosed in parentheses with a subscript 10, indicating it's in base 10 This subscript is used to indicate the number system. For example, (3107)8(3107)_{8} - notice the subscript is 8, so it's no longer decimal but octal Also, why don't we usually write it this way? Because decimal is so common that it's assumed by default
  2. Besides this notation, there's also the suffix letter method you might encounter: For example, 3107H - adding the letter H after a number indicates it's a hexadecimal number

This (3107)10(3107)_{10} can be broken down as:

3×103+1×102+0×101+7×1003×10^3+1×10^2+0×10^1+7×10^0

Now let's look at a binary number (1101)2(1101)_2, which can also be represented as:

1×23+1×22+0×21+1×201×2^3+1×2^2+0×2^1+1×2^0

Can you now understand why they're called decimal and binary systems?

For number system conversion, binary to decimal is simple. You take:

1×23+1×22+0×21+1×201×2^3+1×2^2+0×2^1+1×2^0

Then calculate in decimal:

8+4+0+18+4+0+1

Which equals (13)10(13)_{10}, so we can write (1101)2(1101)_2=(13)10(13)_{10}

3. What is ASCII Code

  • ASCII (American Standard Code for Information Interchange) - the name is quite long, but let's focus on the word "code"

We know that representing numbers in computers is relatively simple, but how do we represent text? For example, letters like a, b, c, d, punctuation marks, Chinese characters, etc.

Our predecessors came up with an excellent solution: create a table that stores these text symbols

Text Symbol
a
b
c

Then assign numbers to these text symbols in order:

NumberText Symbol
0a
1b
2c

When you need to retrieve them, just use the numbers. Want 'a'? Input 1. Want 'b'? Input 2, and so on (now you might understand the meaning of "code")

So ASCII code table was an early symbol table. How early? 1967, when Americans invented it. Americans only use 26 letters, plus various other symbols, so 128 characters were sufficient to cover everything.

Why 128? As mentioned earlier, computers use binary representation. Starting from number 0, going up to 127, that's exactly 128 numbers.

The smallest number is 0, the largest is 127. If we can represent the largest number, we can represent all smaller numbers too. (1111111)2(1111111)_2 equals 127, which we can expand as:

1×26+1×25+1×24+1×23+1×22+1×21+1×201×2^6+1×2^5+1×2^4+1×2^3+1×2^2+1×2^1+1×2^0

Also, this (1111111)2(1111111)_2 has 7 bits total, so we can say it's a 7-bit ASCII code table.