Skip to content

Commit

Permalink
Fixed Number System readme.md (#721)
Browse files Browse the repository at this point in the history
Fixed markdown formatting for clarity and readability.
Modified charts for better readability.
Edited some explanations to match chart changes and for clarity.
Fixed table of contents and section title links so they work.
Fixed file name for lua example so the link to it works.
Fixed minor spelling errors.
  • Loading branch information
Ettubrute05 authored Nov 27, 2023
1 parent 148d2ac commit d58e5d8
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 111 deletions.
File renamed without changes.
262 changes: 151 additions & 111 deletions Number System/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,35 @@ Number systems are a mathematical system for expressing numbers. A number system
- [Octal](#octal)
- [Decimal](#decimal)
- [Hexadecimal](#hexadecimal)
- [Number Chart](#number-chart)
- [Notation](#notation)
- [Binary Addition and Subtraction](#binary-addition-and-subtraction)
- [Example of Binary Addition](#example-of-binary-addition)
- [Example of Binary Subtraction](#example-of-binary-subtraction)
- [Binary to Decimal Conversion](#binary-to-decimal-conversion)
- [Example of Binary to Decimal Conversion](#example-of-binary-to-decimal-conversion)
- [Binary to Hexadecimal Conversion](#binary-to-hexadecimal-conversion)
- [Example of Binary to Hexadecimal Conversion](#example-of-binary-to-hexadecimal-conversion)
- [Base/Radix Conversion](#baseradix-conversion)
- [Radix to Decimal](#radix-to-decimal)
- [Decimal to Radix](#decimal-to-radix)
- [Example of Radix to Decimal Conversion](#example-of-radix-to-decimal-conversion)
- [Example of Decimal to Radix Conversion](#example-of-decimal-to-radix-conversion)
- [Mixed-Base Number Systems](#mixed-base-number-systems)

## [Types of Number Systems](#types-of-number-systems)

### [Positional Numeral System](#positional-numeral-system)

Positional Notation most commonly uses the decinal system. The symbols used in the decimal number system are the Hindu-Arabic numerals 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. It is positional numeral system and is base 10, which means that each place in the number represents a power of 10, also known as the radix. The place value of each digit is determined by its position in the number, with the most significant digit on the left and the least significant digit on the right. The value of a digit is multiplied by the radix raised to the power of its position. For example, in the number 123, the digit 1 is in the hundreds place, the digit 2 is in the tens place, and the digit 3 is in the ones place. The value of the digit 1 is 100, the value of the digit 2 is 20, and the value of the digit 3 is 3. The sum of these values is 123.
Positional Notation most commonly uses the decimal system. The symbols used in the decimal number system are the Hindu-Arabic numerals 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. It is a positional numeral system and is base 10, which means that each place in the number represents a power of 10, also known as the radix. The place value of each digit is determined by its position in the number, with the most significant digit on the left and the least significant digit on the right. The value of a digit is multiplied by the radix raised to the power of its position. For example, in the number 123, the digit 1 is in the hundreds place, the digit 2 is in the tens place, and the digit 3 is in the ones place. The value of the digit 1 is 100, the value of the digit 2 is 20, and the value of the digit 3 is 3. The sum of these values is 123.

### [Sign-value Notation System](#sign-value-notation-system)

Sign-value notation represents numbers by a series of numeric signs that when added together give the value of the number. The most commonly known exmaple would be Roman Numerals, where I means 1, V means 5, X means 10. Thus IV means 4, IX means 9, and XI means 11. Sign-value notation is mostly historical and is not used commonly in the modern world.
Sign-value notation represents numbers by a series of numeric signs that when added together give the value of the number. The most commonly known example would be Roman Numerals, where I means 1, V means 5, X means 10. Thus IV means 4, IX means 9, and XI means 11. Sign-value notation is mostly historical and is not used commonly in the modern world.

## [Common Positional Number Systems](#common-positional-number-systems)

### [Binary](#binary)

Binary Numbers only have two v, 0 and 1. Binary numbers are used in computers because they are easy to represent using electronic circuits. Binary numbers are also used in digital electronics, such as digital cameras, digital watches, and digital televisions.
Binary Numbers only have two numbers, 0 and 1. Binary numbers are used in computers because they are easy to represent using electronic circuits, 1 representing on and 0 representing off. A single digit in binary is referred to as a bit, and 8 bits are a byte. Binary numbers are also used in digital electronics, such as digital cameras, digital watches, and digital televisions.

### [Octal](#octal)

Expand All @@ -47,170 +56,200 @@ Decimal Numbers have ten characters, 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. Decimal n

Hexadecimal Numbers have sixteen characters, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. The Hexadecimal, or Hex, numbering system is commonly used in computer and digital systems to reduce large strings of binary numbers into a sets of four digits for us to easily read.

| Deciaml | Binary | Octal | Hexadecimal |
|:-------:|:------:|:-----:|:-----------:|
| 0 | 0000 | 0 | 0 |
| 1 | 0001 | 1 | 1 |
| 2 | 0010 | 2 | 2 |
| 3 | 0011 | 3 | 3 |
| 4 | 0100 | 4 | 4 |
| 5 | 0101 | 5 | 5 |
| 6 | 0110 | 6 | 6 |
| 7 | 0111 | 7 | 7 |
| 8 | 1000 | 10 | 8 |
| 9 | 1001 | 11 | 9 |
| 10 | 1010 | 12 | A |
| 11 | 1011 | 13 | B |
| 12 | 1100 | 14 | C |
| 13 | 1101 | 15 | D |
| 14 | 1110 | 16 | E |
| 15 | 1111 | 17 | F |

## [Binary Addition and Subtraction](#binary-addition-subtraction)
Arithmetic operation like addition, subtraction, division and multiplications can be done using binary numbers. The rules for binary addition and subtraction are a bit different than that of decimal number system.

### [Binary Addition](#binary-addition)
Binary addition is done by adding the digits starting from the right side of the numbers, in the same way as we add two or more base 10 numbers. In binary addition, the place values are given as ones, twos, fours, eights, sixteens, etc. We first add the digits in one's column, then we move towards the left, i.e., add the digits in the twos column, then the digits in the fours column, and so on.
The four rules that apply when two binary digits are added are given below:

| A | B | Carry | Sum |
|:---:|:---:|:-----:|:-----:|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 0 |
### [Number Chart](#number-chart)

This chart shows how to represent 0-16 in these four numbering systems.

| Binary | Octal | Decimal | Hexadecimal |
|:------:|:-----:|:-------:|:-----------:|
| 00000 | 0 | 0 | 0 |
| 00001 | 1 | 1 | 1 |
| 00010 | 2 | 2 | 2 |
| 00011 | 3 | 3 | 3 |
| 00100 | 4 | 4 | 4 |
| 00101 | 5 | 5 | 5 |
| 00110 | 6 | 6 | 6 |
| 00111 | 7 | 7 | 7 |
| 01000 | 10 | 8 | 8 |
| 01001 | 11 | 9 | 9 |
| 01010 | 12 | 10 | A |
| 01011 | 13 | 11 | B |
| 01100 | 14 | 12 | C |
| 01101 | 15 | 13 | D |
| 01110 | 16 | 14 | E |
| 01111 | 17 | 15 | F |
| 10000 | 20 | 16 | 10 |

### [Notation](#notation)

Here some ways to specify what numbering system you are using, ### here is used to denote any number in that system. The following examples will use the first notation method.

| Numbering System | Notation 1 | Notation 2 | Notation 3 | Notation 4 |
|:----------------:|:----------:|:----------:|:----------:|:----------:|
| Binary: | ###$_{2}$ | 0b### | bin(###) | radix_2 |
| Octal: | ###$_{8}$ | 0o### | oct(###) | radix_8 |
| Decimal: | ###$_{10}$ | 0d### | dec(###) | radix_10 |
| Hexadecimal: | ###$_{16}$ | 0x### | hex(###) | radix_16 |

## [Binary Addition and Subtraction](#binary-addition-and-subtraction)
Arithmetic operations like addition, subtraction, division and multiplications can be done using binary numbers. The rules for binary addition and subtraction are a bit different than that of decimal number system.

### [Example of Binary Addition](#example-of-binary-addition)
Binary addition is done by adding the digits starting from the right side of the numbers, in the same way as we add two or more base 10 numbers. In binary addition, the place values are given, from right to left, as ones, twos, fours, eights, sixteens, etc. We first add the digits in the ones column, then we move towards the left, i.e., add the digits in the twos column, then the digits in the fours column, and so on.
The four rules that apply when two binary digits are added are below given A + B:

| | A | B | Carry | Sum |
|:-------:|:---:|:---:|:-----:|:-----:|
| Rule 1: | 0 | 0 | 0 | 0 |
| Rule 2: | 0 | 1 | 0 | 1 |
| Rule 3: | 1 | 0 | 0 | 1 |
| Rule 4: | 1 | 1 | 1 | 0 |

Steps for Binary Addition:

Step 1: Write all the digits of both the numbers in separate columns as per their place values.
<pre>
1 0 0 1

1 0 1
+ 1 0 1
_______

1 0
____________
</pre>

____________
Step 2: Start from the right-most column digits, 1 and 1. Apply rule 4 above of binary addition which says 1 + 1 = 0 with a carry of 1, so the 1 carries over to the next column, and the 0 goes in the first column of the answer.
<pre>
1 0 0 1

Step 2: Start from the right-most column digits, 1 and 0. Apply one of the rules of binary addition which says 1 + 0 = 1.
+ 1 0 1
_______
0
</pre>

1 0 1

1 0
____________
Step 3: Move to the next column to the left. Here, we have the digits 0 and 0. Apply rule 1 above of binary addition which says 0 + 0 = 0. Next add the carry by applying rule 3 which says 1 + 0 = 1
<pre>
1
____________

Step 3: Move to the next column to the left. Here, we have two digits 0 and 1. Look at the rules given above and find out which rule will be applied here. Apply one of the binary addition rules which says 0 + 1 = 1.
1 0 0 1

1 0 1
+ 1 0 1
_______
1 0
</pre>

1 0
___________
1 1
___________
Step 4: Move to the next column to the left. Here, we have two digits 0 and 1. Look at the rules given above and find out which rule will be applied here. Apply rule 2 which says 0 + 1 = 1.
<pre>
1 0 0 1

Step 4: Now, in the last column, we have only 1 left, so we can apply the rule, 1 + 0 = 1.
+ 1 0 1
_______
1 1 0
</pre>

1 0 1
Step 5: Now, in the last column, we have only 1 left, so we can apply rule 2, 0 + 1 = 1.
<pre>
1 0 0 1

1 0
__________
1 1 1
__________
+ 1 0 1
_______
1 1 1 0
</pre>

Therefore, by adding **(101)** with **(10)**, we get **(111)** as the final answer.
Therefore, by adding **$1001_{2}$** with **$101_{2}$**, we get **$1110_{2}$** as the final answer.

### [Binary Subtraction](#binary-subtraction)
This operation is similar to the basic arithmetic subtraction performed on decimal numbers in Maths. Hence, when we subtract 1 from 0, we need to borrow 1 from the next higher order digit, to reduce the digit by 1 and the remainder left here is also 1
### [Example of Binary Subtraction](#example-of-binary-subtraction)
This operation is similar to the basic arithmetic subtraction performed on decimal numbers in Maths. Hence, when we subtract 1 from 0, we need to borrow 1 from the next higher order digit, to reduce the digit by 1 and the remainder left here is also 1.

The four rules that apply when two binary digits are subtracted are given below:
The four rules that apply when two binary digits are subtracted are below given A - B:

| A | B | Borrow|Difference |
|:---:|:---:|:-----:|:---------:|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | 0 | 0 |
| | A | B | Borrow|Difference |
|:-------:|:---:|:---:|:-----:|:---------:|
| Rule 1: | 0 | 0 | 0 | 0 |
| Rule 2: | 0 | 1 | 1 | 1 |
| Rule 3: | 1 | 0 | 0 | 1 |
| Rule 4: | 1 | 1 | 0 | 0 |

Steps for binary subtraction:

Step 1: First consider the 1’s column, and subtract the one’s column,( 0 – 1 ) and it gives the result 1 as per the condition of binary subtraction with a borrow of 1 from the 10’s place.

Step 1: First consider the ones (1s) column, and subtract the numbers, 0 – 1 and it gives the result 1 as per the condition of binary subtraction with a borrow of 1 from the twos (10s) column: 10 - 1 = 1.
<pre>
1 0 1 0

1 0 1
____________
- 1 0 1
_______

____________
</pre>

Step 2: After borrowing 1 from the 10’s column, the value 1 in the 10’s column is changed into the value 0
Step 2: After borrowing 1 from the twos (10s) column, the value 1 in the twos (10s) column is changed into the value 0.

1 Borrow

<pre>
1 0 1 0

1 0 1
____________
- 1 0 1
_______
1
____________

Step 3: So, subtract the value in the 10’s place, ( 0 – 0 ) = 0.
</pre>

Step 3: So, subtract the value in the twos (10s) place: 0 – 0 = 0.
<pre>
1 0 1 0

1 0 1
___________
- 1 0 1
_______
0 1
___________

Step 4: Now subtract the values in 100’s place. Borrow 1 from the 1000’s place ( 0 – 1 ) = 1.
</pre>

Step 4: Now subtract the values in the fours (100s) place. Borrow 1 from the eights (1000s) place: 0 – 1 = 1.
<pre>
1 0 1 1

1 0 1
__________
0 1 0 1
__________
- 1 0 1
_______
0 1 0 1
</pre>

Therefore, by subtracting **(1010)** with **(101)**, we get **(0101)** as the final answer.
Therefore, by subtracting **$1010_{2}$** with **$101_{2}$**, we get **$0101_{2}$** as the final answer, or **$101_{2}$** leaving off the leading 0.

## [Binary to Decimal Conversion](#binary-decimal-conversion)
To convert Binary to decimal, first we write the given binary number and count the powers of 2 from right to left (powers starting from 0). Now, write each binary digit (right to left) with the corresponding powers of 2 from (right to left), such that first binary digit will be multiplied with the greatest power of 2. Add all the products and the final answer will be the required deciaml number
## [Binary to Decimal Conversion](#binary-to-decimal-conversion)
To convert Binary to decimal, first we write the given binary number and count the powers of 2 from right to left (powers starting from 0). Now, write each binary digit (right to left) with the corresponding powers of 2 from (right to left), such that first binary digit will be multiplied with the greatest power of 2. Add all the products and the final answer will be the required decimal number

### [Example of Binary to Decimal Conversion](#example-binary/decimal)
### [Example of Binary to Decimal Conversion](#example-of-binary-to-decimal-conversion)
Given binary number (1101) into a decimal number.
Now, multiplying each digit from MSB to LSB with reducing the power of the base number 2.
Now, multiplying each digit from MSB (Most-Significant Bit, or leftmost digit) to LSB (Least-Significant Bit or rightmost digit) while reducing the power of the base number 2.

1 × 2^3 + 1 × 2^2 + 0 × 2^1 + 1 × 2^0
$= (1)2^3 + (1)2^2 + (0)2^1 + (1)2^0$

= 8 + 4 + 0 + 1
$= 8 + 4 + 0 + 1$

= 13
$= 13$

Thus, the equivalent decimal number for the given binary number (1101) is **(13)**
Thus, the equivalent decimal number for the given binary number **$1101_{2}$** is **$13_{10}$**

## [Binary to Hexadecimal Conversion](#binary-hexadecimal-conversion)
## [Binary to Hexadecimal Conversion](#binary-to-hexadecimal-conversion)
First, you need to convert a binary into other base system (e.g., into decimal, or into octal). Then you need to convert it hexadecimal number.Since number numbers are type of positional number system. That means weight of the positions from right to left are as 160^, 16^1, 16^2, 16^3 and so on. for the integer part and weight of the positions from left to right are as 16^-1, 16^-2, 16^-3 and so on. for the fractional part.

### [Example of Binary to Hexadecimal Conversion](#example-binary/hexadecimal)
### [Example of Binary to Hexadecimal Conversion](#example-of-binary-to-hexadecimal-conversion)
Converting binary number 1101010 into hexadecimal numbers.

First, convert this into a decimal number:

= (1101010)
$= 1101010$

= 1x2^6 + 1x2^5 + 0x2^4 + 1x2^3 + 0x2^2 + 1x2^1 + 0x2^0
$= (1)2^6 + (1)2^5 + (0)2^4 + (1)2^3 + (0)2^2 + (1)2^1 + (0)2^0$

= 64+32+0+8+0+2+0
$= 64 + 32 + 0 + 8 + 0 + 2 + 0$

= (106)
$= 106$

Then, convert it into hexadecimal number

= (106)
$= 106$

= 6x16^1 + 10x16^0
$= (6)16^1 + (10)16^0$

= **(6A)16** which is answer.
Thus **$1101010_{2} = 6A_{16}$**.

**Note:** 4 digits of binary directly correspond to 1 digit of hexadecimal, so if you take the 4 rightmost digits of the example (1010) they directly correspond to A in the answer, and (110) corresponds to 6.


## [Base/Radix Conversion](#baseradix-conversion)
Expand All @@ -219,7 +258,7 @@ Base/Radix conversion is the process to convert the number from one base to anot

[Youtube Video Playlist](https://www.youtube.com/playlist?list=PL0o_zxa4K1BXCpQbUdf0htZE8SS0PYjy-)

### [Radix to Decimal](#radix-to-decimal)
### [Example of Radix to Decimal Conversion](#example-of-radix-to-decimal-conversion)

The basic formula for another radix to decimal conversion is:
$a = r_m b^m + r_{m-1}b^{m-1} + r_{m-2}b^{m-2} + r_{1}b^{1} + r_{0}b^{0}$
Expand All @@ -228,12 +267,13 @@ $0 < r_m < b$ and $0 ≤ r_i < b for i = 0, 1, ... , m − 1$.

Example: Convert 2212 from base 3 (radix_3) to decimal (radix_10)

$a = (2)3^3+(2)3^2+(1)3^1+(2)3^0$
$a = (2)3^3 + (2)3^2 + (1)3^1 + (2)3^0$

$a = 77$

Thus $2212_{3} = 77_{10}$.

### [Decimal to Radix](#decimal-to-radix)
### [Example of Decimal to Radix Conversion](#example-of-decimal-to-radix-conversion)

The basic algorithm for decimal to another radix conversion is to take the decimal number and divide it by the new base/radix. The remainder is the rightmost digit of the new number. The quotient is the new number to be converted. The process is repeated until the quotient is zero.

Expand Down

0 comments on commit d58e5d8

Please sign in to comment.