11 · Introducing the TCP_IP Internet Layer, IPv4 Addressing, and Subnets認識 TCP/IP 網際網路層、IPv4 定址與子網路

Decimal-to-Binary Conversion十進位轉二進位

The process of converting a decimal number to a binary number can be simplified by using a table. The table method utilizes elementary mathematics like addition and subtraction. This process is simple and effective. With a bit of practice, you will learn it quickly.

將十進位數字轉換為二進位數字的過程,可以透過使用表格來簡化。表格法運用的是加法與減法等基礎數學。這個過程既簡單又有效,只要稍加練習,你就能很快學會。

When converting from decimal into binary, the idea is to find the right sequence of bits by marking placeholders as 1 or 0. All bits are represented, and each placeholder marked with 1 adds its value to the converted number, while 0s are ignored. For example, 255 is represented by marking all placeholders with 1, meaning that summing up each placeholder value produces the decimal number: 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255.

從十進位轉換為二進位時,重點在於透過將每個位值標記為 1 或 0 來找出正確的位元序列。所有位元都會被表示出來,每個標記為 1 的位值都會把該值加進轉換後的數字,而 0 則會被忽略。舉例來說,255 是把所有位值都標記為 1,也就是將每個位值加總後得出的十進位數字:128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255。

The process of converting a decimal number into binary is done by marking the closest (lower) placeholder as 1 and subtracting the corresponding value from the decimal number until there is no remainder. Any unused or skipped placeholders are marked as 0. The binary representation of the decimal number is the 1 and 0 sequence that is produced.

將十進位數字轉換為二進位的做法,是把最接近(且較小)的位值標記為 1,再從該十進位數字中減去對應的值,直到沒有餘數為止。任何未使用或跳過的位值則標記為 0。所產生的 1 與 0 序列,就是該十進位數字的二進位表示。

BaseExponent
基數指數
27
27
26
26
25
25
24
24
23
23
22
22
21
21
20
20
Place Value
位值
128
128
64
64
32
32
16
16
8
8
4
4
2
2
1
1
Convert decimal
147 to binary
將十進位
147 轉換為二進位
1
1
0
0
0
0
1
1
0
0
0
0
1
1
1
1
147
147
(271)+
(271)+
(260)+
(260)+
(250)+
(250)+
(241)+
(241)+
(230)+
(230)+
(220)+
(220)+
(211)+
(211)+
(201)
(201)
147
147
(1281)+
(1281)+
(161)+
(161)+
(21)+
(21)+
(11)
(11)
147
147
1 + 0 + 0 + 1 + 0 + 0 + 1 + 1
1 + 0 + 0 + 1 + 0 + 0 + 1 + 1
147 = 10010011
147 = 10010011

This figure illustrates the conversion of decimal number 147 to binary. Start by making a table with all of the 2exponent values listed, for exponent values 0 through 7, as shown in the first row of the table. Add a row that lists the decimal value of each of these exponents, as shown in the second row. These are the positional or place values (and are also called placeholders). The binary number is put in the third row as it is determined. The following table describes the steps for converting the number 147 to a binary number.

此圖說明將十進位數字 147 轉換為二進位的過程。首先建立一個表格,列出指數值 0 到 7 所對應的所有 2指數 值,如表格第一列所示;再新增一列,列出每個指數所對應的十進位值,如第二列所示,這些即為位置值(也稱為位值)。二進位數字則依決定順序填入第三列。下表說明將數字 147 轉換為二進位數字的步驟。

Procedure for Converting a Decimal Number to a Binary Number

將十進位數字轉換為二進位數字的程序

Step
步驟
Action
動作
1.
1.
Start by making a table with all of the 2exponent values listed, for exponent values 0 through 7, as shown in the first row of the table. Add a row that lists the decimal value of each of these exponents, as shown in the second row; these are the place values.
首先建立一個表格,列出指數值 0 到 7 所對應的所有 2指數 值,如表格第一列所示。新增一列,列出每個指數所對應的十進位值,如第二列所示;這些就是位值。
2.
2.
Looking at the table columns, what is the greatest power of 2 that is less than or equal to 147? 128 is less than or equal to 147, so place a 1 in the 27 = 128 column.
查看表格欄位,小於或等於 147 的最大 2 的次方是多少?128 小於或等於 147,所以在 27 = 128 這一欄填入 1。
3.
3.
Calculate how much is left over by subtracting 128 from 147. The result is 19.
計算 147 減去 128 後剩下多少,結果是 19。
4.
4.
Now look for the next greatest power of 2 that is less than or equal to 19. The next place value is 64, which is not less than or equal to 19, so place a 0 in that column.
接著找出小於或等於 19 的下一個最大 2 的次方。下一個位值是 64,並非小於或等於 19,因此在該欄填入 0。
5.
5.
The next place value is 32, which again is not less than or equal to 19, so place a 0 in that column as well.
下一個位值是 32,同樣並非小於或等於 19,因此該欄也填入 0。
6.
6.
The next place value is 16, which is less than or equal to 19. Place a 1 in that column. Calculate how much is left over by subtracting 16 from 19. The result is 3.
下一個位值是 16,小於或等於 19,在該欄填入 1。計算 19 減去 16 後剩下多少,結果是 3。
7.
7.
Now look for the next greatest power of 2 that is less than or equal to 3. The next place value is 8, which is not less than or equal to 3, so place a 0 in that column.
接著找出小於或等於 3 的下一個最大 2 的次方。下一個位值是 8,並非小於或等於 3,因此在該欄填入 0。
8.
8.
The next place value is 4, which is not less than or equal to 3, so place a 0 in that column too.
下一個位值是 4,並非小於或等於 3,因此該欄也填入 0。
9.
9.
The next place value is 2, which is less than or equal to 3. Place a 1 in that column. Calculate how much is left over by subtracting 2 from 3. The result is 1.
下一個位值是 2,小於或等於 3,在該欄填入 1。計算 3 減去 2 後剩下多少,結果是 1。
10.
10.
Now look for the next greatest power of 2 that is less than or equal to 1. The next place value (which is also the final place value) is 1, which is equal to 1, so place a 1 in the last column.
接著找出小於或等於 1 的下一個最大 2 的次方。下一個位值(同時也是最後一個位值)是 1,等於 1,因此在最後一欄填入 1。
11.
11.
The binary equivalent of the decimal number 147 is 10010011.
十進位數字 147 對應的二進位等值是 10010011。

You can also have a number that is smaller than 128, for example, 35. 35 in decimal converts to 00100011 in binary. Note that the first 2 bits of the binary number are zeros; these zeros are known as leading zeros. Recall that IPv4 addresses are most often written in the dotted-decimal notation, which consists of four sets of 8-bits (octets) converted from binary to decimal numbers, separated by dots. For IPv4 addresses, you will always use 8 bits when converting each of the decimal numbers to binary. Some of these binary numbers may have leading zeroes.

你也可能遇到小於 128 的數字,例如 35。十進位的 35 轉換成二進位是 00100011。請注意,這個二進位數字的前 2 個位元都是 0,這些 0 稱為前導零。回想一下,IPv4 位址最常以點分十進位表示法寫成,由四組 8 位元(八位元組)由二進位轉換為十進位數字、並以點號分隔所組成。對於 IPv4 位址,每個十進位數字轉換為二進位時一律使用 8 位元,其中有些二進位數字可能會帶有前導零。

Interactive content from the online course (not available offline)線上課程的互動內容(離線版未收錄)
What is the binary equivalent of the decimal number 183?十進位數字 183 對應的二進位等值是什麼?
Which option is the binary representation of 80?80 的二進位表示是下列哪一個選項?