110 likes | 350 Views
รหัส (Codes). วัตถุประสงค์ของบทเรียน รู้จักรหัสแบบต่างๆ ศึกษาประโยชน์ของรหัสแต่ละประเภท ศึกษาวิธีการแปลงรหัส ศึกษาวิธีการเข้ารหัสและถอดรหัส. Number Representation Codes. Straight binary code: Represents numbers using natural or straight binary form (this is a weighted code)
E N D
รหัส (Codes) วัตถุประสงค์ของบทเรียน • รู้จักรหัสแบบต่างๆ • ศึกษาประโยชน์ของรหัสแต่ละประเภท • ศึกษาวิธีการแปลงรหัส • ศึกษาวิธีการเข้ารหัสและถอดรหัส A. Yaicharoen
Number Representation Codes Straight binary code: Represents numbers using natural or straight binary form (this is a weighted code) Decimal codes: Use binary to represent a decimal value • Weighted decimal codes The location of each bit contains related weight. Example: BCD (or 8421) code, 2421 code, 7536' code, or 5043210 code • Nonweighted decimal codes The location of each bit has no related weight. Example: Excess-3 code, 2-out-of-5 code A. Yaicharoen
Code Conversion Decimal to BCD code conversion (VS straight binary) 1 9 2 8 (decimal) 0001 1001 0010 1000 (BCD) 0111 1000 1000 (binary) A. Yaicharoen
Unit-Distance Codes Use when convert analog quantity to digital representation Only one bit change between two successive integer numbers Example: Gray code A. Yaicharoen
+ + + Code Conversion Binary code to Gray code conversion 1 0 0 1 (binary) 1 1 0 1 (Gray) A. Yaicharoen
+ + + Code Conversion Gray code to Binary code conversion 1 1 0 1 (Gray) 1 0 0 1 (binary) A. Yaicharoen
Alphanumeric codes Use binary to represent characters Number of bits in these codes depends on number of characters these codes represented. Example: ASCII (American Standard Code for Information Interchange) is 7-bit code Unicode Standard is 16-bit code A. Yaicharoen
Error Detection Codes เป็นรหัสที่สามารถตรวจสอบได้ว่ามีความผิดพลาดในการรับ-ส่ง หรือไม่ แบ่งเป็น 2 ประเภทคือ 1. ประเภทที่สามารถตรวจสอบข้อผิดพลาดได้จากตัวรหัสเอง เช่น รหัส 2-out-of-5, biquinary 2. ประเภทที่ต้องมีการเพิ่มเติมข้อมูลลงไปในรหัสเพื่อใช้ในการ ช่วยตรวจสอบข้อผิดพลาด เช่น การเพิ่ม parity bit - odd parity เป็น 1 เพื่อให้จำนวนของ 1 เป็นจำนวนคี่ - even parity เป็น 1 เพื่อให้จำนวนของ 1 เป็นจำนวนคู่ A. Yaicharoen
Error Correction Codes เป็นรหัสที่มีการเพิ่มเติมข้อมูลลงไปเพื่อช่วยให้สามารถ 1. ตรวจสอบว่าข้อมูลผิดพลาดหรือไม่ 2. ถ้าข้อมูลผิดก็สามารถบอกตำแหน่งที่ผิดพลาดได้ ตัวอย่างของรหัสนี้ได้แก่ Hamming code สำหรับข้อมูลขนาด 4 bit จำเป็นต้องเพิ่มข้อมูลของ parity อีก 3 bit ในระบบของ Hamming code โดยจะอยู่ในรูปของ p1 p2 b1 b2 p3 b3 b4 (หนังสือบางเล่มจะเป็น b4 b3 b2 p3 b1 p2 p1) จำนวนของ parity bit (k) ที่จะเติมลงในรหัสที่มีข้อมูลจำนวน m bit หาได้จาก m 2k - k - 1 A. Yaicharoen
Hamming Code จำนวนของ parity bit (k) ที่จะเติมลงในรหัสที่มีข้อมูลจำนวน m bit จำนวนข้อมูล จำนวนของ parity bit 2-4 3 5-11 4 12-26 5 27-57 6 58-120 7 ตำแหน่งของ parity bit ที่ใช้ตรวจสอบตำแหน่งของข้อมูลที่ผิดพลาด ตำแหน่งของ parity bit ตำแหน่งของข้อมูล 1 1,3,5,7,9,11,13,15,17,... 2 2,3,6,7,10,11,14,15,18,... 4 4,5,6,7,12,13,14,15,20,... 8 8,9,10,11,12,13,14,15,24,... A. Yaicharoen
Hamming Code Parity bit ที่ตำแหน่ง i (pi) จะเป็น even parity ที่เติมเข้าไป โดยคิดจากตำแหน่ง ของข้อมูลใน bit ต่างๆที่เกี่ยวข้อง เช่น p1 จะได้จากการนำข้อมูลใน bit ที่ 3, 5, 7,... ดังนั้น ถ้าข้อมูลใน bit ที่ 3, 5, และ 7 เป็น 0, 1, และ 1 ตามลำดับ จะได้ p1 = 0 (จาก 0 1 1) การตรวจสอบว่าข้อมูลใน bit ใดผิดพลาด สามารถทำได้โดย 1. หาค่าของ check bit จากการหา even parity ของ parity bit ที่ i กับ ข้อมูลในบิตที่เกี่ยวข้อง 2. นำข้อมูลทั้งหมดมาเรียงกัน ค่าที่ได้คือตำแหน่งที่เกิดความผิดพลาด เช่น p1p2p3 = 011 หมายความว่า ตำแหน่งที่ 3 ของข้อมูลเกิดความผิดพลาด A. Yaicharoen