الأنظمة الرقمية والأعداد الثنائية
مقدمة في تصميم المنطق الرقمي، تشمل الإشارات التناظرية والرقمية، أنظمة العد (الثنائي، الثماني، العشري، السداسي عشر)، التحويل بين الأنظمة، والعمليات الحسابية الثنائية باستخدام المتممات.
Digital Systems and Binary Numbers
Introduction to digital logic design, covering analog and digital signals, number systems (binary, octal, decimal, hexadecimal), base conversions, and binary arithmetic using complements.
أهداف التعلم
- شرح الأنظمة والتصميم الرقمي والفرق بين الإشارات التناظرية والرقمية.
- فهم أنظمة العد المستخدمة في الحواسيب الرقمية (الثنائي، الثماني، السداسي عشر) وكيفية التحويل بينها.
- إجراء العمليات الحسابية على الأعداد الثنائية بما في ذلك الجمع والطرح باستخدام المتممات.
- Explain Digital Systems/Design and the difference between analog and digital signals.
- Learn the number systems used in digital computers (Binary, Octal, and Hexadecimal) and how to convert between them.
- Learn how to perform arithmetic operations on binary numbers including addition and subtraction using complements.
1 الإشارات التناظرية مقابل الرقمية
1 Analog vs. Digital Signals
الإشارات التناظرية مستمرة ولها قيم لا نهائية، بينما الإشارات الرقمية متقطعة ولها قيم محدودة (مثل 0 و 1).
Analog signals are continuous with infinite values, while digital signals are discrete with limited values (like 0 and 1).
تحمل الإشارات المعلومات التي نهتم بمعالجتها.
الإشارة التناظرية (Analog) هي كمية فيزيائية تتغير باستمرار مع الزمن (مثل الصوت) ويمكن أن تأخذ عددًا لا نهائيًا من القيم في نطاق معين.
أما الإشارة الرقمية (Digital) فتأخذ قيمًا متقطعة (Discrete) ومحدودة. في الأنظمة الرقمية الثنائية، تُمثل هذه القيم بالرقمين 0 و 1، أو (خطأ وصواب)، أو مستويات جهد مثل 0 فولت و +5 فولت.
Signals carry information we want to manipulate.
An analog signal is a physical quantity that varies continuously with time (like sound) and can have an infinite number of values in a range.
A digital signal takes on discrete, limited values. In binary digital systems, these are represented by digits 0 and 1, False (F) and True (T), or voltage levels like 0 Volt and +5 Volt.
الأنظمة الرقمية أكثر مقاومة للتشويش (Noise) مقارنة بالأنظمة التناظرية لأنها تعتمد على مستويات جهد محددة (عتبات) بدلاً من القيم الدقيقة.
هذا يجعل تخزين ومعالجة ونقل البيانات الرقمية أكثر موثوقية في أجهزة الكمبيوتر والهواتف الذكية.
Digital systems are more resilient to noise compared to analog systems because they rely on specific voltage thresholds rather than exact values.
This makes storing, processing, and transmitting digital data much more reliable in computers and smartphones.
| Analog Signals | Digital Signals | |
|---|---|---|
| طبيعة القيم Nature of Values | مستمرة (عدد لا نهائي من القيم) Continuous (Infinite number of values) | متقطعة (عدد محدود من القيم) Discrete (Limited number of values) |
| التمثيل في الزمن Time Representation | مستمرة في الزمن Continuous in time | متقطعة في الزمن (تتغير عند دورات الساعة) Discrete in time (changes at clock cycles) |
لماذا تستخدم أجهزة الكمبيوتر الحديثة الإشارات الرقمية بدلاً من التناظرية رغم أن العالم الحقيقي تناظري؟ Why do modern computers use digital signals instead of analog ones, even though the real world is analog?
لأن الإشارات الرقمية أسهل في التخزين، وأقل عرضة للتشويش، ويمكن معالجتها بدقة عالية باستخدام الدوائر المنطقية.
Because digital signals are easier to store, less susceptible to noise, and can be processed with high precision using logic circuits.
2 تمثيل الأنظمة العددية
2 Number Systems Representation
أي عدد يُكتب كقيمة تعتمد على موضع الخانة (الوزن) مضروباً في أساس النظام (Radix).
Any number is written as a value depending on its digit position (weight) multiplied by the base (Radix).
يُمثل العدد ذو الأساس r بسلسلة من الأرقام، حيث يمثل كل رقم وزنًا يعتمد على موضعه. يُفصل الجزء الصحيح عن الجزء الكسري بنقطة الأساس (Radix point).
يتم حساب القيمة الإجمالية (المقدار) عن طريق جمع حاصل ضرب كل رقم في وزنه (الأساس مرفوعًا لأس الموضع).
على سبيل المثال، في النظام العشري (الأساس 10)، الرقم 512.74 يُحسب كـ: 5×10² + 1×10¹ + 2×10⁰ + 7×10⁻¹ + 4×10⁻².
A number with radix r is represented by a string of digits, where each digit represents a weight based on its position. The integer portion is separated from the fraction portion by a radix point.
The total magnitude is calculated by summing the product of each digit and its weight (Base raised to the position power).
For example, in decimal (base 10), 512.74 is: 5×10² + 1×10¹ + 2×10⁰ + 7×10⁻¹ + 4×10⁻².
هذا التمثيل متعدد الحدود (Polynomial expansion) هو أساس كل أنظمة العد الموضعية.
يسمح لنا هذا المفهوم الرياضي الموحد بتحويل أي نظام عد (ثنائي، ثماني، سداسي عشر) إلى النظام العشري ببساطة عن طريق تطبيق نفس المعادلة مع تغيير قيمة الأساس (r).
This polynomial expansion is the foundation of all positional number systems.
This unified mathematical concept allows us to convert any number system (binary, octal, hex) to decimal simply by applying the same formula and changing the base value (r).
| Binary | Octal | Decimal | Hexadecimal | |
|---|---|---|---|---|
| الأساس (Radix) Base (Radix) | 2 2 | 8 8 | 10 10 | 16 16 |
| الأرقام المستخدمة Digits Used | 0, 1 0, 1 | 0 إلى 7 0 to 7 | 0 إلى 9 0 to 9 | 0-9 و A-F 0-9 and A-F |
ما هو أكبر رقم يمكن استخدامه في نظام العد الثماني (Base 8)؟ ولماذا؟ What is the largest digit that can be used in the Octal (Base 8) number system? And why?
الرقم 7. لأن نظام الأساس r يستخدم الأرقام من 0 إلى r-1.
The digit 7. Because a base r system uses digits from 0 to r-1.
3 التحويل من النظام العشري إلى الأنظمة الأخرى
3 Base Conversions: Decimal to Others
لتحويل الجزء الصحيح: اقسم على الأساس وخذ الباقي. لتحويل الجزء الكسري: اضرب في الأساس وخذ العدد الصحيح.
To convert integer part: Divide by base and take remainder. To convert fraction part: Multiply by base and take integer.
لتحويل عدد عشري إلى أي نظام آخر (مثل الثنائي أو الثماني أو السداسي عشر)، نقسم العملية إلى جزأين:
- الجزء الصحيح: نقسم العدد العشري على الأساس المطلوب (مثلاً 2 للثنائي). الباقي يمثل الخانة الأقل أهمية (LSB). نستمر في قسمة الناتج حتى نصل إلى صفر.
- الجزء الكسري: نضرب الكسر في الأساس المطلوب. الجزء الصحيح من الناتج يمثل الخانة الأكثر أهمية (MSB) للكسر. نستمر في ضرب الجزء الكسري المتبقي حتى نصل إلى صفر أو دقة معينة.
To convert a decimal number to another base (like binary, octal, or hex), we split the process:
- Integer part: Divide the decimal number by the target base (e.g., 2 for binary). The remainder forms the Least Significant Bit (LSB). Repeat dividing the quotient until it reaches 0.
- Fraction part: Multiply the fraction by the target base. The integer part of the result forms the Most Significant Bit (MSB) of the fraction. Repeat multiplying the remaining fraction until it reaches 0 or a desired precision.
هذه الخوارزمية تعمل لأننا نقوم فعلياً بعكس عملية التوسيع متعدد الحدود.
القسمة المتكررة تستخرج المعاملات (الأرقام) من الأصغر وزناً إلى الأكبر، بينما الضرب المتكرر للكسور يستخرج المعاملات من الأكبر وزناً (بعد الفاصلة مباشرة) إلى الأصغر.
This algorithm works because we are essentially reversing the polynomial expansion.
Repeated division extracts the coefficients (digits) from lowest weight to highest, while repeated multiplication of fractions extracts coefficients from highest weight (just after the point) to lowest.
ماذا يحدث إذا لم يصل الجزء الكسري إلى الصفر عند الضرب المتكرر؟ What happens if the fractional part never reaches zero during repeated multiplication?
الرقم الكسري يكون دورياً (يتكرر إلى المالانهاية) في النظام الجديد، ونتوقف عند الوصول إلى الدقة المطلوبة (عدد معين من الخانات).
The fractional number is repeating (infinite) in the new base, and we stop when we reach the desired precision (a specific number of bits).
4 التحويلات السريعة: الثنائي والثماني والسداسي عشر
4 Fast Base Conversions: Binary, Octal, and Hex
كل رقم ثماني يمثل 3 بتات، وكل رقم سداسي عشر يمثل 4 بتات. التحويل بينها يتم بتجميع أو فك البتات مباشرة.
Every octal digit represents 3 bits, and every hex digit represents 4 bits. Conversion is done by directly grouping or expanding bits.
لأن 8 هي 2³ و 16 هي 2⁴، هناك علاقة مباشرة بين النظام الثنائي والأنظمة الثمانية والسداسية عشر.
- من ثنائي إلى سداسي عشر: قسّم العدد الثنائي إلى مجموعات من 4 بتات (بدءاً من الفاصلة يميناً ويساراً)، واستبدل كل مجموعة بالرقم السداسي عشر المقابل. أضف أصفاراً (Pad with Zeros) إذا لزم الأمر.
- من ثنائي إلى ثماني: نفس الطريقة ولكن بمجموعات من 3 بتات.
للتحويل العكسي، استبدل كل رقم ثماني أو سداسي عشر بما يعادله من البتات.
Because 8 is 2³ and 16 is 2⁴, there is a direct relationship between binary and the octal/hexadecimal systems.
- Binary to Hex: Group the binary bits into sets of 4 (starting from the radix point moving left for integers and right for fractions), and replace each group with its hex equivalent. Pad with zeros if necessary.
- Binary to Octal: Same method, but use groups of 3 bits.
To convert back, simply expand each octal or hex digit into its 3-bit or 4-bit binary equivalent.
تُستخدم الأنظمة الثمانية والسداسية عشر بشكل أساسي كطريقة مختصرة (Shorthand) لكتابة الأرقام الثنائية الطويلة التي يصعب على البشر قراءتها.
لا تفهم أجهزة الكمبيوتر النظام السداسي عشر، بل تفهم الثنائي فقط، لكن المبرمجين يستخدمونه لتبسيط الكود وعناوين الذاكرة.
Octal and Hexadecimal systems are primarily used as a shorthand for writing long binary numbers that are hard for humans to read.
Computers do not understand hex; they only understand binary. Programmers use hex to simplify code and memory addresses.
كيف تحول من النظام الثماني إلى السداسي عشر؟ How do you convert from Octal to Hexadecimal?
لا توجد طريقة مباشرة بسيطة. يجب تحويل الرقم الثماني إلى ثنائي أولاً (كل رقم إلى 3 بتات)، ثم إعادة تجميع البتات في مجموعات من 4 للحصول على السداسي عشر.
There is no simple direct way. You must convert the octal number to binary first (each digit to 3 bits), then regroup the bits into sets of 4 to get the hexadecimal number.
5 الجمع الثنائي
5 Binary Addition
الجمع الثنائي يشبه العشري، لكن 1 + 1 = 10 (صفر ومعنا 1)، و 1 + 1 + 1 = 11 (واحد ومعنا 1).
Binary addition is like decimal, but 1 + 1 = 10 (0 carry 1), and 1 + 1 + 1 = 11 (1 carry 1).
قواعد جمع البتات الأساسية هي: 0+0=0، 0+1=1، 1+0=1.
عندما نجمع 1+1، الناتج هو 2 بالعشري، والذي يكتب 10 بالثنائي، لذا نكتب 0 ونرفع (Carry) 1 للخانة التالية.
إذا كان لدينا 1+1+1 (بسبب وجود Carry سابق)، الناتج هو 3 بالعشري، والذي يكتب 11 بالثنائي، لذا نكتب 1 ونرفع 1.
يتم إجراء الجمع عمودياً (Column Addition) من اليمين إلى اليسار تماماً كما في النظام العشري.
The basic bit addition rules are: 0+0=0, 0+1=1, 1+0=1.
When adding 1+1, the result is 2 in decimal, which is 10 in binary, so we write 0 and carry over 1 to the next column.
If we have 1+1+1 (due to a previous carry), the result is 3 in decimal, which is 11 in binary, so we write 1 and carry over 1.
Column addition is performed from right to left exactly like in decimal.
في الدوائر الرقمية، يتم تنفيذ هذه القواعد باستخدام بوابات منطقية (Logic Gates).
جمع بتين يتم باستخدام دائرة (Half Adder)، بينما جمع ثلاثة بتات (بتين + Carry) يتم باستخدام دائرة (Full Adder).
In digital circuits, these rules are implemented using logic gates.
Adding two bits is done using a Half Adder circuit, while adding three bits (two bits + carry-in) is done using a Full Adder circuit.
في النظام العشري، متى نقوم بترحيل (Carry) رقم للخانة التالية؟ وكيف يقارن ذلك بالنظام الثنائي؟ In decimal, when do we carry a digit to the next column? How does this compare to binary?
في العشري نرحل عندما يكون المجموع 10 أو أكثر (الأساس). في الثنائي نرحل عندما يكون المجموع 2 أو أكثر (الأساس). القاعدة العامة: نرحل عندما المجموع ≥ الأساس.
In decimal, we carry when the sum is 10 or more (the base). In binary, we carry when the sum is 2 or more (the base). General rule: Carry when Sum ≥ Base.
6 المتممات والطرح الثنائي
6 Complements and Binary Subtraction
المتمم الأول يقلب البتات (0 إلى 1 والعكس). المتمم الثاني هو المتمم الأول + 1. نستخدم المتمم الثاني لتحويل الطرح إلى جمع.
1's complement flips bits (0 to 1 and vice versa). 2's complement is 1's complement + 1. We use 2's complement to turn subtraction into addition.
تُستخدم المتممات لتبسيط عملية الطرح في الدوائر الرقمية، بحيث يمكن استخدام دائرة الجمع نفسها للطرح.
- المتمم الأول (1's complement): يتم الحصول عليه بقلب كل 0 إلى 1 وكل 1 إلى 0.
- المتمم الثاني (2's complement): يتم الحصول عليه بإيجاد المتمم الأول ثم إضافة 1 للناتج.
لطرح N من M (أي M - N): نجمع M مع المتمم الثاني لـ N.
إذا نتج عن الجمع Carry إضافي في النهاية، نتجاهله ويكون الناتج موجباً. إذا لم ينتج Carry، فهذا يعني أن النتيجة سالبة، وللحصول على القيمة الفعلية نأخذ المتمم الثاني للناتج ونضيف إشارة سالب.
Complements are used to simplify subtraction in digital circuits, allowing the same addition circuit to perform subtraction.
- 1's complement: Obtained by changing all 0s to 1s and 1s to 0s.
- 2's complement: Obtained by finding the 1's complement and adding 1.
To subtract N from M (M - N): Add M to the 2's complement of N.
If a carry is produced at the end, discard it; the result is positive. If no carry is produced, the result is negative; to get the familiar form, take the 2's complement of the result and add a minus sign.
استخدام المتمم الثاني يحل مشكلة وجود تمثيلين للصفر (صفر موجب وصفر سالب) التي تظهر في المتمم الأول، مما يجعل العمليات الحسابية أكثر كفاءة في المعالجات الحديثة (ALU).
Using 2's complement solves the problem of having two representations for zero (+0 and -0) that exists in 1's complement, making arithmetic operations much more efficient in modern processors (ALU).
لماذا نتجاهل الـ Carry الأخير عند طرح رقم صغير من رقم كبير باستخدام المتمم الثاني؟ Why do we discard the final carry when subtracting a smaller number from a larger number using 2's complement?
لأن هذا الـ Carry يمثل تجاوزاً لسعة الخانات المحددة (Overflow) الناتج عن عملية الجمع الوهمية، وتجاهله يعيد الرقم إلى النطاق الصحيح الموجب.
Because this carry represents an overflow beyond the specified number of bits caused by the artificial addition process, and discarding it brings the number back to the correct positive range.