Binary, Denary, and Hexadecimal เลขฐานสอง ฐานสิบ และฐานสิบหก

Place values in base-10, base-2, and base-16 ค่าประจำหลักในระบบฐาน 10, ฐาน 2 และฐาน 16

A number system uses a fixed set of digits and place values based on powers of the base. Denary (decimal) is base-10, binary is base-2, and hexadecimal is base-16. Computers store bits, so binary is natural; hex is a compact way to write byte-sized values. The same value can be written in each base — for example, 255 in denary is 11111111 in binary and FF in hexadecimal.

ระบบเลขใช้ชุดหลักที่จำกัด และมีค่าประจำหลักเป็นกำลังของฐาน ฐานสิบ (denary/decimal) คือ base-10 ฐานสองคือ base-2 และฐานสิบหกคือ base-16 คอมพิวเตอร์เก็บบิต จึงใช้ฐานสองเป็นหลัก ส่วนฐานสิบหกช่วยเขียนค่าไบต์ให้สั้นลง ค่าเดียวกันเขียนได้หลายฐาน — เช่น 255 ฐานสิบ คือ 11111111 ฐานสอง และ FF ฐานสิบหก

Digit positions show place values หลักของตัวเลขคือตำแหน่งของตัวเลข

The number 255 uses three digits in denary, eight bits in binary, and two hex digits. Empty cells mean that place is not used in that representation.

ตัวเลข 255 ใช้ 3 หลักในฐานสิบ 8 บิตในฐานสอง และ 2 หลักในฐานสิบหก ช่องว่างหมายถึงหลักนั้นไม่ได้ใช้ในการเขียนแบบนั้น

Place (N) หลัก (N) 7 6 5 4 3 2 1 0
Denary (base 10) ฐานสิบ — — — — — 2 5 5
Binary (base 2) ฐานสอง 1 1 1 1 1 1 1 1
Hexadecimal (base 16) ฐานสิบหก — — — — — — F F

Digits and bases หลักที่ใช้ในแต่ละฐาน

  • Denary (base-10): digits 0–9; place values \(10^N\) ฐานสิบ (base-10): หลัก 0–9; ค่าประจำหลัก \(10^N\)
  • Binary (base-2): digits 0 and 1 only; place values \(2^N\) (often written 0b…) ฐานสอง (base-2): ใช้ได้แค่ 0 และ 1; ค่าประจำหลัก \(2^N\) (มักเขียน 0b…)
  • Hexadecimal (base-16): digits 0–9 and A–F (10–15); place values \(16^N\) (often 0x…) ฐานสิบหก (base-16): หลัก 0–9 และ A–F (แทน 10–15); ค่าประจำหลัก \(16^N\) (มักเขียน 0x…)

Place-value calculation example ตัวอย่างการคำนวณค่าในแต่ลัก

Each digit is multiplied by its place value; the sum equals 255 in every base below.

แต่ละหลักคูณด้วยค่าประจำหลักของตำแหน่งนั้น แล้วนำมารวมกันได้ 255 ในทุกฐานด้านล่าง

Base ฐาน 7 6 5 4 3 2 1 0 Total รวม
Denary (base 10) ฐานสิบ — — — — — \(2 \times 10^2\) \(5 \times 10^1\) \(5 \times 10^0\) 255
Binary (base 2) ฐานสอง \(1 \times 2^7\) \(1 \times 2^6\) \(1 \times 2^5\) \(1 \times 2^4\) \(1 \times 2^3\) \(1 \times 2^2\) \(1 \times 2^1\) \(1 \times 2^0\) 255
Hexadecimal (base 16) ฐานสิบหก — — — — — — \(15 \times 16^1\) \(15 \times 16^0\) 255

1 Denary place values 1 ค่าประจำหลักฐานสิบ

In denary, the rightmost digit is ones (\(10^0\)), then tens (\(10^1\)), hundreds (\(10^2\)), and so on. Use print() to show the expanded sum for 1289.

ในฐานสิบ หลักขวาสุดคือหน่วย (\(10^0\)) แล้วเป็นหลักสิบ (\(10^1\)) หลักร้อย (\(10^2\)) ตามลำดับ ใช้ print() แสดงการกระจายผลรวมของเลข 1289

[1]
[output]
1000
200
80
9
1289

2 Binary place values and bin() 2 ค่าประจำหลักฐานสอง และ bin()

Binary place values are powers of 2: … 8, 4, 2, 1. For 1011 (binary), sum the places where the bit is 1. bin(n) converts a denary integer to a binary string prefixed with 0b.

ค่าประจำหลักฐานสองเป็นกำลังของ 2 เช่น … 8, 4, 2, 1 สำหรับ 1011 (ฐานสอง) ให้บวกเฉพาะหลักที่บิตเป็น 1 bin(n) แปลงจำนวนเต็มฐานสิบเป็นสตริงฐานสองที่ขึ้นต้นด้วย 0b

[2]
[output]
11
0b1011
11

3 Hexadecimal digits and hex() 3 หลักฐานสิบหก และ hex()

Hex digits A–F mean 10–15. One byte (0–255) needs at most two hex digits. hex(n) returns a string with prefix 0x. Use int("…", 16) to parse a hex digit string back to denary.

หลัก A–F ในฐานสิบหกแทนค่า 10–15 หนึ่งไบต์ (0–255) ใช้เลขฐานสิบหกได้อย่างมาก 2 หลัก hex(n) คืนสตริงที่ขึ้นต้นด้วย 0x ใช้ int("…", 16) เพื่อแปลงสตริงฐานสิบหกกลับเป็นฐานสิบ

[3]
[output]
26
0x1a
26
255

Note: Run uses a JavaScript simulator, not real Python. For real Python, try Google Colab. หมายเหตุ: ปุ่ม Run จำลองด้วย JavaScript ไม่ใช่ Python จริง หากต้องการ Python จริง ลองใช้ Google Colab

References References / แหล่งอ้างอิง

Sources used for place values and bases:

แหล่งที่ใช้ประกอบเนื้อหาค่าประจำหลักและระบบฐาน:

  1. Numeral systems — Wikipedia — Positional notation / Hexadecimal (bases and place values) (ฐานและค่าประจำหลัก)
  2. Python bin / hex — Built-in Functions — bin / hex (used in the demos) (ใช้ในตัวอย่าง Run)

End-of-lesson quizแบบฝึกหัดท้ายบท

ตอบแล้ว 0 / 10

ข้อ 1

1 / 10

What is the name of the number system with digits 0–9?ระบบเลขที่มีหลัก 0–9 เรียกว่าอะไร?

เฉลย / Answerซ่อนเฉลย / Hide

เฉลย / Answer: (A) Denary / decimal (base-10)ฐานสิบ (denary / decimal)

คำอธิบายแต่ละตัวเลือก / Explanation for each choice

  • (A) Denary / decimal (base-10)ฐานสิบ (denary / decimal)
    Correct! Denary uses digits 0–9.ถูกต้อง! ฐานสิบใช้หลัก 0–9
  • (B) Binaryฐานสอง (binary)
    Wrong: binary uses only 0 and 1.ผิด: ฐานสองมีหลักแค่ 0 และ 1
  • (C) Hexadecimalฐานสิบหก (hexadecimal)
    Wrong: hex has 16 digits including A–F.ผิด: ฐานสิบหกมี 16 หลัก รวม A–F
  • (D) A one-bit systemระบบบิตเดียว
    Wrong: not a standard number-system name in this lesson.ผิด: ไม่ใช่ชื่อระบบเลขมาตรฐานในบทนี้

ข้อ 2

2 / 10

Binary place values use powers of which number?ค่าประจำหลักของฐานสองใช้กำลังของจำนวนใด?

เฉลย / Answerซ่อนเฉลย / Hide

เฉลย / Answer: (B) 22

คำอธิบายแต่ละตัวเลือก / Explanation for each choice

  • (A) 1010
    Wrong: 10 is the denary base.ผิด: 10 เป็นฐานของ denary
  • (B) 22
    Correct! Binary place values are 2^N.ถูกต้อง! ค่าประจำหลักฐานสองคือ 2^N
  • (C) 1616
    Wrong: 16 is the hexadecimal base.ผิด: 16 เป็นฐานของ hexadecimal
  • (D) 88
    Wrong: 8 is bits per byte, not the binary base.ผิด: 8 คือจำนวนบิตในหนึ่งไบต์ ไม่ใช่ฐานของ binary

ข้อ 3

3 / 10

What is the denary value of binary 1011?เลขฐานสอง 1011₂ มีค่าฐานสิบเท่าใด?

เฉลย / Answerซ่อนเฉลย / Hide

เฉลย / Answer: (C) 1111

คำอธิบายแต่ละตัวเลือก / Explanation for each choice

  • (A) 1313
    Wrong: 13 is 1101 in binary, not 1011.ผิด: 13 คือค่าของ 1101₂ ไม่ใช่ 1011₂
  • (B) 99
    Wrong: that misses some place values.ผิด: คำนวณค่าประจำหลักไม่ครบ
  • (C) 1111
    Correct! 8+0+2+1 = 11.ถูกต้อง! 8+0+2+1 = 11
  • (D) 1515
    Wrong: 15 is 1111 in binary.ผิด: 15 คือ 1111₂

ข้อ 4

4 / 10

In hexadecimal, what denary value does digit A represent?ในฐานสิบหก หลัก A แทนค่าฐานสิบเท่าใด?

เฉลย / Answerซ่อนเฉลย / Hide

เฉลย / Answer: (D) 1010

คำอธิบายแต่ละตัวเลือก / Explanation for each choice

  • (A) 1111
    Wrong: 11 is digit B.ผิด: 11 คือค่าของหลัก B
  • (B) 1616
    Wrong: 16 is the base, not digit A.ผิด: 16 คือฐาน ไม่ใช่ค่าของหลัก A
  • (C) 11
    Wrong: A does not mean 1.ผิด: A ไม่ได้แทน 1
  • (D) 1010
    Correct! A = 10, B = 11, …, F = 15.ถูกต้อง! A = 10, B = 11, …, F = 15

ข้อ 5

5 / 10

What is 255 in denary written in hexadecimal?เลขฐานสิบ 255 เขียนเป็นฐานสิบหกได้เป็นอะไร?

เฉลย / Answerซ่อนเฉลย / Hide

เฉลย / Answer: (A) FFFF

คำอธิบายแต่ละตัวเลือก / Explanation for each choice

  • (A) FFFF
    Correct! Denary 255 = hex FF (15×16 + 15).ถูกต้อง! 255 ฐานสิบ = FF ฐานสิบหก (15×16 + 15)
  • (B) FEFE
    Wrong: FE equals 254 in denary, not 255.ผิด: FE = 254 ฐานสิบ ไม่ใช่ 255
  • (C) 255255
    Wrong: 255 is denary notation, not hexadecimal.ผิด: 255 เป็นค่าฐานสิบ ไม่ใช่การเขียนในฐานสิบหก
  • (D) 1111111111111111
    Wrong: 11111111 is binary, not hexadecimal.ผิด: 11111111 เป็นฐานสอง ไม่ใช่ฐานสิบหก

ข้อ 6

6 / 10

Why do computers use the binary system?ทำไมคอมพิวเตอร์จึงใช้ระบบฐานสอง?

เฉลย / Answerซ่อนเฉลย / Hide

เฉลย / Answer: (B) Because they store data as bits that are only 0 or 1เพราะเก็บข้อมูลด้วยบิตที่มีค่าได้แค่ 0 และ 1

คำอธิบายแต่ละตัวเลือก / Explanation for each choice

  • (A) Because humans find binary easiest to readเพราะมนุษย์อ่านฐานสองง่ายที่สุด
    Wrong: humans usually prefer denary.ผิด: มนุษย์คุ้นฐานสิบมากกว่า
  • (B) Because they store data as bits that are only 0 or 1เพราะเก็บข้อมูลด้วยบิตที่มีค่าได้แค่ 0 และ 1
    Correct! Bits have only two values, so binary fits.ถูกต้อง! บิตมีได้แค่สองค่า จึงใช้ฐานสอง
  • (C) Because it has digits A–Fเพราะมีหลัก A–F
    Wrong: A–F belong to hexadecimal.ผิด: A–F อยู่ในฐานสิบหก
  • (D) Because one byte has 10 bitsเพราะหนึ่งไบต์มี 10 บิต
    Wrong: one byte has 8 bits.ผิด: หนึ่งไบต์มี 8 บิต

ข้อ 7

7 / 10

At most how many hexadecimal digits are needed to represent one byte?หนึ่งไบต์แทนด้วยเลขฐานสิบหกได้อย่างมากกี่หลัก?

เฉลย / Answerซ่อนเฉลย / Hide

เฉลย / Answer: (C) 2 digits2 หลัก

คำอธิบายแต่ละตัวเลือก / Explanation for each choice

  • (A) 1 digit1 หลัก
    Wrong: one hex digit covers only 0–15.ผิด: 1 หลักฐานสิบหกครอบคลุมได้แค่ 0–15
  • (B) 8 digits8 หลัก
    Wrong: 8 is the bit count, not hex digits per byte.ผิด: 8 เป็นจำนวนบิต ไม่ใช่จำนวนหลัก hex ของหนึ่งไบต์
  • (C) 2 digits2 หลัก
    Correct! 16×16 = 256 = 2^8 covers one byte.ถูกต้อง! 16×16 = 256 = 2^8 จึงพอสำหรับหนึ่งไบต์
  • (D) 10 digits10 หลัก
    Wrong: that is not how many hex digits a byte needs.ผิด: ไม่ใช่จำนวนหลัก hex ต่อไบต์

ข้อ 8

8 / 10

Why is 1102 written as binary incorrect?เลข 1102₂ ผิดหลักการของฐานสองเพราะอะไร?

เฉลย / Answerซ่อนเฉลย / Hide

เฉลย / Answer: (D) Because digit 2 is not allowed in binaryเพราะมีหลัก 2 ซึ่งไม่ใช่หลักที่อนุญาตในฐานสอง

คำอธิบายแต่ละตัวเลือก / Explanation for each choice

  • (A) Because it is longer than 8 bitsเพราะยาวเกิน 8 บิต
    Wrong: length is not the issue here.ผิด: ความยาวไม่ใช่เหตุผลหลักในตัวอย่างนี้
  • (B) Because it must include letters A–Fเพราะต้องมีตัวอักษร A–F
    Wrong: A–F are for hexadecimal.ผิด: A–F ใช้ในฐานสิบหก
  • (C) Because it starts with 1เพราะขึ้นต้นด้วย 1
    Wrong: starting with 1 is fine in binary.ผิด: การขึ้นต้นด้วย 1 ถูกต้องในฐานสอง
  • (D) Because digit 2 is not allowed in binaryเพราะมีหลัก 2 ซึ่งไม่ใช่หลักที่อนุญาตในฐานสอง
    Correct! Binary allows only 0 and 1.ถูกต้อง! ฐานสองใช้ได้แค่ 0 และ 1

ข้อ 9

9 / 10

What is the denary value of binary 11111111?เลขฐานสอง 11111111 มีค่าฐานสิบเท่าใด?

เฉลย / Answerซ่อนเฉลย / Hide

เฉลย / Answer: (C) 255255

คำอธิบายแต่ละตัวเลือก / Explanation for each choice

  • (A) 128128
    Wrong: 128 is only the value of binary 10000000.ผิด: 128 คือค่าของ 10000000₂ เท่านั้น
  • (B) 254254
    Wrong: 254 is 11111110 in binary, not 11111111.ผิด: 254 คือ 11111110₂ ไม่ใช่ 11111111₂
  • (C) 255255
    Correct! All place values sum to 255 (128+64+32+16+8+4+2+1).ถูกต้อง! บวกค่าประจำหลักทุกหลักได้ 255 (128+64+32+16+8+4+2+1)
  • (D) 256256
    Wrong: 256 is 2^8, one more than binary 11111111.ผิด: 256 คือ 2^8 ซึ่งมากกว่า 11111111₂ หนึ่งหน่วย

ข้อ 10

10 / 10

What is the place value of the rightmost digit in every base taught here?ค่าประจำหลักของหลักขวาสุดในทุกฐานที่สอนในบทนี้คืออะไร?

เฉลย / Answerซ่อนเฉลย / Hide

เฉลย / Answer: (B) Base to the power 0, which equals 1ฐานยกกำลัง 0 ซึ่งมีค่าเป็น 1

คำอธิบายแต่ละตัวเลือก / Explanation for each choice

  • (A) Always base to the power 1ฐานยกกำลัง 1 เสมอ
    Wrong: the rightmost place uses power 0.ผิด: หลักขวาสุดใช้กำลัง 0
  • (B) Base to the power 0, which equals 1ฐานยกกำลัง 0 ซึ่งมีค่าเป็น 1
    Correct! 10^0, 2^0, and 16^0 all equal 1.ถูกต้อง! 10^0, 2^0 และ 16^0 ล้วนเท่ากับ 1
  • (C) Equal to the number of bits in a byteเท่ากับจำนวนบิตในไบต์
    Wrong: that is unrelated to the ones place.ผิด: ไม่เกี่ยวกับค่าประจำหลักขวาสุด
  • (D) Always 255เท่ากับ 255 เสมอ
    Wrong: 255 is an unsigned byte maximum, not the ones place.ผิด: 255 เป็นค่าสูงสุดของหนึ่งไบต์แบบไม่ติดเครื่องหมาย