SlideShare une entreprise Scribd logo
1  sur  26
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
เน็กเกชัน
ในระบบรูปแบบเครื่องหมายจำานวน
การแปลงเลขจำานวนบวกเป็นเลขจำานวน
ลบนั้นทำาได้ง่ายมาก คือเพียงแต่เปลี่ยนบิต
“เครื่องหมายให้เป็น 1” เท่านั้น ส่วนใน
ระบบทูคอมพลีเมนต์จะต้องมีสองขั้นตอน
ดังนี้
1. เปลี่ยนบิตทุกบิตรวมทั้งบิต
เครื่องหมายให้กลายเป็นบิตตรงกันข้าม
“นั่นคือเปลี่ยนบิต 0” “ให้เป็น 1” และ
เน็กเกชัน
ในระบบรูปแบบเครื่องหมายจำานวน
การแปลงเลขจำานวนบวกเป็นเลขจำานวน
ลบนั้นทำาได้ง่ายมาก คือเพียงแต่เปลี่ยนบิต
“เครื่องหมายให้เป็น 1” เท่านั้น ส่วนใน
ระบบทูคอมพลีเมนต์จะต้องมีสองขั้นตอน
ดังนี้
1. เปลี่ยนบิตทุกบิตรวมทั้งบิต
เครื่องหมายให้กลายเป็นบิตตรงกันข้าม
“นั่นคือเปลี่ยนบิต 0” “ให้เป็น 1” และ
การคำานวณคณิตศาสตร์ของการคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็มเลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของการคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็มเลขจำานวนเต็มเน็กเกชันเน็กเกชัน
การคำานวณคณิตศาสตร์ของการคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็มเลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของการคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็มเลขจำานวนเต็ม
การบวกและการลบ
ในการบวกเลข (addition) ใด ๆ
ก็ตาม ผลลัพธ์ที่ได้อาจมีขนาดใหญ่กว่า
ขนาดของข้อมูลที่นำามาบวกกัน ซึ่งเรียก
สถานการณ์นี้ว่าการเกิด overflow
เมื่อมี overflow เกิดขึ้นหน่วยเอแอลยู
จะส่งสัญญาณเตือนนี้เพื่อไม่ให้นำา
ผลลัพธ์ที่ได้ไปใช้งาน การตรวจสอบ
สถานะ overflow จะใช้กฎเกณฑ์ดังนี้
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็มการบวกและการลบ
แสดงการบวกเลขสองจำานวนที่อยู่ในรูปแบบ
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็มการบวกและการลบ
การลบ (subtraction) ก็
สามารถทำาได้ง่ายโดยการใช้กฎ
ดังนี้ การลบเลขตัวลบออกจากตัว
ตั้ง ให้แปลงเลขตัวลบให้เป็นรูป
แบบทูคอมพลีเมนต์แล้วนำามาบวก
เข้ากับตัวตั้ง ดังนั้นการลบจะ
สามารถคำานวณค่าได้จากการบวก
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การบวกและการลบ
แสดงการลบเลขจำานวนที่อยู่ในรูปแบบทูคอมพลี
การคำานวณคณิตศาสตร์ของการคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็มเลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของการคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็มเลขจำานวนเต็มการบวกและการลบ
รูปแสดงไดอะแกรมแบบบล็อกแสดงส่วนประกอบ
ฮาร์ดแวร์
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็มการคูณ
เมื่อเปรียบเทียบกับการบวกและ
การลบแล้ว การคูณ
(multiplication) เป็นการทำางานที่มี
ความสลับซับซ้อนกว่ามาก ไม่ว่าจะ
ใช้ฮาร์ดแวร์หรือซอฟต์แวร์ในการ
ทำางาน ได้มีการคิดค้นอัลกอริทึม
สำาหรับการคูณขึ้นใช้งานในเครื่อง
คอมพิวเตอร์มากมายหลายแบบ
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคูณ เลขจำานวนเต็มที่ไม่มี
เครื่องหมาย
รูปแสดงการคูณเลขจำานวนเต็มไบนารี่แบบที่ไม่มี
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคูณเลขจำานวนเต็มที่ไม่มี
เครื่องหมาย
1. การคูณทำาให้เกิดผลการคูณชั่วคราว
หนึ่งจำานวนต่อทุกบิตของตัวคูณ ผลชั่วคราวนี้
จะถูกนำามาบวกเข้าด้วยกันเพื่อสร้างผลลัพธ์
สุดท้าย
2. ผลการคูณชั่วคราวสามารถสร้างขึ้นได้
“โดยง่ายคือ ถ้าบิตตัวคูณเป็น 0” ผลการคูณ
“ชั่วคราวก็จะเป็น 0” ทั้งหมด และถ้าบิตตัวคูณ
“เป็น 1” ผลการคูณชั่วคราวก็คือตัวตั้งนั่นเอง
3. ผลลัพธ์สุดท้ายคือการนำาผลชั่วคราว
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคูณเลขจำานวนเต็มที่ไม่มี
เครื่องหมาย
เมื่อเปรียบเทียบกับการคูณด้วยมือแล้ว
การคูณด้วยเครื่องคอมพิวเตอร์ได้รับการ
ปรับปรุงวิธีการให้มีประสิทธิภาพสูงกว่ามาก
ประการแรก ผลการคูณชั่วคราวจะถูกนำา
มาบวกเข้าด้วยกันในทันทีที่ทำาได้ แทนที่จะต้อง
รอให้ได้ครบทุกตัวเสียก่อน ซึ่งช่วยขจัดปัญหา
การเก็บรักษาผลการคูณชั่วคราวเอาไว้ ทำาให้
ประหยัดรีจิสเตอร์ไปได้
การคำานวณคณิตศาสตร์ของการคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็มเลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของการคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็มเลขจำานวนเต็ม
รูปแสดงส่วนประกอบฮาร์ดแวร์ที่ใช้ในการคูณ
เลขจำานวนเต็ม
การคูณ เลขจำานวนเต็มที่
ไม่มีเครื่องหมาย
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคูณ - การคูณเลขทูคอมพลีเมน
ต์
รูปแสดงการคูณเลขสองจำานวนที่ไม่มีเครื่องหมาย
ขนาด 4-bit
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคูณเลขทูคอม
พลีเมนต์
รูปแสดงการเปรียบเทียบการคูณเลขไมมี
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็มการคูณ - การคูณเลขทูคอม
พลีเมนต์
นักออกแบบทั่วไปไม่ชอบการ
แปลงผลคูณกลับเป็นเลขทูคอมพลี
เมนต์ในขั้นตอนสุดท้าย วิธีการที่
นิยมใช้กันมากที่สุดวิธีหนึ่งคือ
Booth’s algorithm ซึ่งยังเป็นวิธี
การที่ช่วยเพิ่มความเร็วในการคูณ
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคูณ
-การคูณเลขทู
คอมพลีเมนต์
รูปแสดง Booth’s algorithm สำาหรับการคูณ
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคูณเลขทูคอมพลีเมนต์
รูปแสดง Booth’s algorithm สำาหรับการรูปแสดง Booth’s algorithm สำาหรับการ
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็มการคูณเลขทูคอมพลีเมนต์
รูปแสดงตัวอย่าง Booth’s algorithm สำาหรับ
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็มการหาร
กระบวนการหาร (division) มี
ความซับซ้อนมากกว่ากระบวนการคูณ
แต่ก็ใช้หลักการพื้นฐานที่เหมือนกัน
เริ่มต้นด้วยการหารด้วยมือ และ
กระบวนการเลื่อนบิต และการบวก และ
การลบเลข
รูปแสดงตัวอย่างการหารเลขฐานสองแบบไม่มี
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็มการหาร
กระบวนการเริ่มด้วยการตรวจ
สอบเลขตัวตั้ง (dividend) mละบิต
จากซ้ายไปขวา จนกว่ากลุ่มของบิตที่
ตรวจสอบนั้นจะเป็นตัวเลขที่มีค่าไม่
น้อยกว่าเลขตัวหาร (divisor) นั่นคือ
การตรวจสอบว่าตัวหารนั้นสามารถ
นำามาหารตัวตั้งได้ ในเวลาเดียวกับ
ที่ทำาการตรวจสอบนั้น ผลการหารจะ
การคำานวณคณิตศาสตร์ของการคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็มเลขจำานวนเต็ม
การหาร
รูปแสดงผังงานของการหารเลขฐานสองแบบไม่มี
การคำานวณ
คณิตศาสตร์
ของ
เลขจำานวน
เต็ม (การ
หาร)
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็มการหาร
1. อ่านค่าตัวหารเข้ามาเก็บไว้ในรีจิ
สเตอร์ M และตัวตั้งในรีจิสเตอร์ A และ
Q โดยตัวตั้งจะต้องอยู่ในรูปของเลข
ฐานสองแบบทูคอมพลีเมนต์ขนาด 2n
บิต เช่น เลข 4 บิต 0111 จะอยู่ในรูป
00000111 และ 1001 จะอยู่ในรูป 111
11001 เป็นต้น
2. เลื่อน (shift) รีจิสเตอร์ A, Q ไป
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็มการหาร
4. การทำางานในขั้นตอนที่ 3 จะ
ถือว่าสำาเร็จ ถ้าค่าของบิตเครื่องหมาย
ในรีจิสเตอร์ A มีค่าเท่าเดิม (บิต
เครื่องหมายก่อนการทำางานและหลังการ
ทำางานต้องเหมือนเดิม)
a. ถ้าเครื่องหมายบิตถูกต้อง
หรือ A = 0
ให้กำาหนดค่า Q0  1
b. ถ้าเครื่องหมายไม่ถูกต้อง
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การคำานวณคณิตศาสตร์ของ
เลขจำานวนเต็ม
การหาร
6. เศษที่เหลือจากการหารจะอยู่
ในรีจิสเตอร์ A ถ้าบิตเครื่องหมาย
ของตัวตั้งและตัวหารยังคงเหมือน
เดิม แสดงว่าผลหารอยู่ในรีจิสเตอร์
Q มิฉะนั้นผลหารที่ถูกต้องคือ ค่าทู
คอมพลีเมนต์ของตัวเลขที่อยู่รีจิส
เตอร์ Q

Contenu connexe

En vedette

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 

En vedette (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

การคำนวณคณิตศาสตร์ของเลขจำนวนเต็ม