Sie sind auf Seite 1von 7

*What is a number system? The number system in a computer is actually called the binary number system.

The binary number system is a base two number system meaning only two numbers are used. These two numbers are represented by 0 and 1. Technically it is "the usual base-2 system with a positional notation with a radix of 2" en.wikipedia.org/wiki/Binary_numeral_system

*Give the importance of number systems. When humans are speaking to one another, they speak in a particular language. This language is made of words and letters. Although we type words and letters in the computer, the computer does not understand the words and letters. Rather, those words and letters are translated into numbers. Computers talk and understand in numbers. As a computer programmer or an IT professional, you need to understand the three most common number systems that are frequently used in computers. Those number systems are: Decimal Hexadecimal Binary If you have an understanding of the number systems, you will understand the following topics in computer science: You will understand how to calculate network addresses You will understand how to read memory address locations in core dumps

You will understand the color definitions in web and application programming You will understand many other concepts *List down the most common number systems used in computers. Decimal System o base 10 o valid digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary System o base 2 o valid digits - 0, 1 Octal System o base 8 o valid digits - 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal System o base 16 o valid digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F o A refers to decimal 10, B refers to decimal 11, etc.

*Enumerate the steps in converting a decimal number to any number system, any number system to decimal number system, and any to any number system. Convert From Any Base To Decimal Let's think more carefully what a decimal number means. For example, 1234 means that there are four boxes (digits); and there are 4 one's in the right-most box (least significant digit), 3 ten's in the

next box, 2 hundred's in the next box, and finally 1 thousand's in the left-most box (most significant digit). The total is 1234: Original Number: 1 2 3 4 | | | | How Many Tokens: 1 2 3 4 Digit/Token Value: 1000 100 10 1 Value: 1000 + 200 + 30 + 4 = 1234 or simply, 1*1000 + 2*100 + 3*10 + 4*1 = 1234 Thus, each digit has a value: 10^0=1 for the least significant digit, increasing to 10^1=10, 10^2=100, 10^3=1000, and so forth. Likewise, the least significant digit in a hexadecimal number has a value of 16^0=1 for the least significant digit, increasing to 16^1=16 for the next digit, 16^2=256 for the next, 16^3=4096 for the next, and so forth. Thus, 1234 means that there are four boxes (digits); and there are 4 one's in the right-most box (least significant digit), 3 sixteen's in the next box, 2 256's in the next, and 1 4096's in the left-most box (most significant digit). The total is: 1*4096 + 2*256 + 3*16 + 4*1 = 4660 Example. Convert the hexadecimal number 4B3 to decimal notation. What about the decimal equivalent of the hexadecimal number 4B3.3? Solution: 4 B | | How Many Tokens: 4 11 Digit/Token Value: 256 16 Value: 1024 +176 = 1203.1875 Original Number: 3 | 3 1 + 3 . 3 | 3 0.0625 + 0.1875

Convert From Decimal to Any Base Again, let's think about what you do to obtain each digit. As an example, let's start with a decimal number 1234 and convert it to decimal notation. To extract the last digit, you move the decimal point left by one digit, which means that you divide the given number by its base 10. 1234/10 = 123 + 4/10 The remainder of 4 is the last digit. To extract the next last digit, you again move the decimal point left by one digit and see what drops out. 123/10 = 12 + 3/10 The remainder of 3 is the next last digit. You repeat this process until there is nothing left. Then you stop. In summary, you do the following: Quotient Remainder ----------------------------1234/10 = 123 4 --------+ 123/10 = 12 3 ------+ | 12/10 = 1 2 ----+ | | 1/10 = 0 1 --+ | | | (Stop when the quotient is 0.) | | | | 1 2 3 4 (Base 10) Now, let's try a nontrivial example. Let's express a decimal number 1341 in binary notation. Note that the desired base is 2, so we repeatedly divide the given decimal number by 2. Quotient Remainder
----------------------------1341/2 = 670 1 ----------------------+ 670/2 = 335 0 --------------------+ | 335/2 = 167 1 ------------------+ | | 167/2 = 83 1 ----------------+ | | | 83/2 = 41 1 --------------+ | | | | 41/2 = 20 1 ------------+ | | | | | 20/2 = 10 0 ----------+ | | | | | | 10/2 = 5 0 --------+ | | | | | | |

5/2 = 2/2 = 1/2 = quotient is 0)

2 1 0

1 ------+ | | | | | | | | 0 ----+ | | | | | | | | | 1 --+ | | | | | | | | | |

(Stop when the

| | | | | | | | | | | 1 0 1 0 0 1 1 1 1 0 1 (BIN; Base 2) Let's express the same decimal number 1341 in octal notation. Quotient Remainder ----------------------------1341/8 = 167 5 --------+ 167/8 = 20 7 ------+ | 20/8 = 2 4 ----+ | | 2/8 = 0 2 --+ | | | (Stop when the quotient is 0) | | | | 2 4 7 5 (OCT; Base 8) Let's express the same decimal number 1341 in hexadecimal notation. Quotient Remainder ----------------------------1341/16 = 83 13 ------+ 83/16 = 5 3 ----+ | 5/16 = 0 5 --+ | | (Stop when the quotient is 0) | | | 5 3 D (HEX; Base 16) Example. Convert the decimal number 3315 to hexadecimal notation. What about the hexadecimal equivalent of the decimal number 3315.3? Solution: Quotient Remainder ----------------------------3315/16 = 207 3 ------+ 207/16 = 12 15 ----+ | 12/16 = 0 12 --+ | | | | | C F 3

(Stop when the quotient is 0) (HEX; Base 16)

(HEX; Base 16) Product Integer Part 0.4 C C C ... -------------------------------| | | | 0.3*16 = 4.8 4 ----+ | | | | | 0.8*16 = 12.8 12 ------+ | | | | 0.8*16 = 12.8 12 --------+ | | | 0.8*16 = 12.8 12 ----------+ | | : ---------------------+ : Thus, 3315.3 (DEC) --> CF3.4CCC... (HEX)

Note that from the Base Conversion Table, you can easily get the binary notation from the hexadecimal number by grouping four binary digits per hexadecimal digit, or from or the octal number by grouping three binary digits per octal digit, and vice versa. HEX 5 3 D BIN 0101 0011 1101 OCT 2 4 7 5 BIN 010 100 111 101 Finally, the fractional part is a decimal number can also be converted to any base by repeatedly multiplying the given number by the target base. Example: Convert a decimal number 0.1234 to binary notation (BIN; Base 2) Product Integer Part 0.0 0 0 1 1 1 1 1 1 0 0 1 ... -------------------------------| | | | | | | | | | | | | 0.1234*2 = 0.2468 0 ----+ | | | | | | | | | | | | 0.2468*2 = 0.4936 0 ------+ | | | | | | | | | | | 0.4936*2 = 0.9872 0 --------+ | | | | | | | | | | 0.9872*2 = 1.9744 1 ----------+ | | | | | | | | | 0.9744*2 = 1.9488 1 ------------+ | | | | | | | | 0.9488*2 = 1.8976 1 --------------+ | | | | | | | 0.8976*2 = 1.7952 1 ----------------+ | | | | | | 0.7952*2 = 1.5904 1 ------------------+ | | | | | 0.5904*2 = 1.1808 1 --------------------+ | | | | 0.1808*2 = 0.3616 0 ----------------------+ | | | 0.3616*2 = 0.7232 0 ------------------------+ | | 0.7232*2 = 1.4464 1 --------------------------+ | : ----------------------------+ :

From Decimal to Binary


Divide the given decimal number by 2, until cant do further dividing. And at the same time write-down the remainder values respectively. First remainder value is the least significant bit (LSB) and the last remainder value is the most significant bit (MSB) of the derived binary number, from the given decimal number.

From Decimal to Hexadecimal


Divide the given decimal number by 16, until cant do further dividing. Then follow the same procedure used to derive the binary number from decimal number.

From Binary to Hexadecimal and Vise Versa


To convert binary number into hexadecimal number, group the binary number into four bits segments. If there is not enough bits to do that it is allow you to add zeros before the most significant bit. Then find the appropriate hexadecimal number through the decimal number of the each four bits segment. Its not difficult. Just you have to keep in mind 00002 to 11112 binary values, along with respective hexadecimal values from 0 H to F H. Those values are included in table Decimal

Numbers and their Binary and Hexadecimal Equivalents. Example:


Code:

111110102 100111012 1010112

= = =

(1111 (1001

1010)2 1101)2

= = =

FA H 9D H 2B H

(0010 1011)2

If you want to convert a hexadecimal number into binary number, just find the relative binary number through decimal numbers for each single digits of hexadecimal number.

Das könnte Ihnen auch gefallen