
Jun 3rd, 2007, 11:04 PM
#1
Thread Starter
PowerPoster
Number Systems for Computer Programmers.
Number Systems for
Computer Programmers.
As a computer programmer, you might have to work with different types of number systems. Starting from well known Decimal Number Systems to Binary and Hexadecimal are the most usable number systems in programming.
In this tutorial I’m going to explain what these systems are and how they interact with each other.
Contents:
 Basic Rules and Definitions
 The Decimal Number System
 The Binary Number System
 Two’sComplement Notation
 The Hexadecimal Number System
 Conversion of One Number System to Another
 From Decimal to Binary
 From Decimal to Hexadecimal
 From Binary to Hexadecimal and Vise Versa
 Decimal Numbers and their Binary and Hexadecimal Equivalents
Last edited by eranga262154; Jun 3rd, 2007 at 11:53 PM.
Reason: Incorrect Placement
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat”  Gautama Buddha

Jun 3rd, 2007, 11:08 PM
#2
Thread Starter
PowerPoster
Basic Rules and Definitions
Before go further I want to point out few basic rules in mathematics, which I’m going to use later in my tutorial.
 Any number to the 0^{th} of power equals to 1.
 Any number to the 1^{st} of power equals to the same number (number itself).
 Any number can be represented as powers of the system’s base.
 The system of base n requires n number of digits.
Following definitions are used;
 Digits of a number is count from right to left and the right most digit is the first digit of that number.
 First digit holds 1^{st} place value, second digit holds 10^{th} place value, third digit holds 100^{th} place value, and so on.
 Most Significant Bit (MSB) is the left most bit of a binary value.
 Least Significant Bit (LSB) is the right most bit of a binary value.
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat”  Gautama Buddha

Jun 3rd, 2007, 11:15 PM
#3
Thread Starter
PowerPoster
The Decimal Number System
The decimal number system is base10 system and it is the most common number system that you use everyday. It requires 10 different digits, from 0 to 9.
For an example, 154is expressed as powers of 10. The digit 4 (first digit) gives 10 to the 0 power, digit 5 (second digit) gives 10 to the 1 power, and so on.
Number 154 can be deploying as follows.
Code:
1 1 x 10^{2} = 1 x 100 = 100
5 5 x 10^{1} = 5 x 10 = 50
4 4 x 10^{0} = 4 x 1 = 4
Sum = 154 (Decimal)
Mathematical representation of 154 in base10 is, 154_{10}. But it can be written as 154 without any uncertainty.
Last edited by eranga262154; Jun 4th, 2007 at 12:21 AM.
Reason: Incomplete
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat”  Gautama Buddha

Jun 3rd, 2007, 11:25 PM
#4
Thread Starter
PowerPoster
The Binary Number System
The binary number system is base2. Hence it requires only two digits, 0 and 1. This binary number system is very useful for computer programmers, because it has two stages and can be used to represent the digital on/off status in which computer chips and memory work.
Here’s an example for a binary number, 1101. It is “OneOneZeroOne”, is the way that a binary number is pronouncing, digitbydigit from lefttoright, as usual.
Its representation in the decimal format, which you’re more familiar with is as follows.
Code:
1 1 x 2^{3} = 1 x 8 = 8
1 1 x 2^{2} = 1 x 4 = 4
0 0 x 2^{1} = 0 x 2 = 0
1 1 x 2^{0} = 1 x 1 = 1
Sum = 13 (decimal)
Once again, standard representation of a binary number is, 1101_{2}.
Two’sComplement Notation
Two’scomplement notation is an efficient way of representing signed numbers in computer chips and memory. When a number is written in two’scomplement notation, the most significant bit of the number represent its sign; 0 means that the number is positive, 1 means the number is negative.
A positive number can be written in two’scomplement notation is the same as the number written in unsigned notation, and although the most significant bit must be zero.
A negative number can be written in two’scomplement notation by inverting all of the bits of its absolute value, and then adding one to the result.
Example:
Code:
1 = 0001_{2} 1 = 1110_{2} + 1_{2} = 1111_{2}
2 = 0010_{2} 2 = 1101_{2} + 1_{2} = 1110_{2}
8 = 1000_{2} 8 = 0111_{2} + 1_{2} = 1000_{2}
9 = 0101_{2} 9 = 1010_{2} + 1_{2} = 1011_{2}
Emphasize that, 1000_{2} represents 8, not 8. That is because the most significant bit is 1, indicating that the number is negative.
Last edited by eranga262154; Jun 4th, 2007 at 12:19 AM.
Reason: Incomplete
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat”  Gautama Buddha

Jun 3rd, 2007, 11:30 PM
#5
Thread Starter
PowerPoster
The Hexadecimal Number System
The hexadecimal system (also called as hex system) is base16, so that it requires 16 different digits. The digits from 0 to 9 are used, along with letters from A to F, which represent the decimal values from 10 to 15 respectively.
1AF is an example for hexadecimal number. Its decimal format;
Code:
1 1 x 162 = 1 x 256 = 256
A A x 161 = 10 x 16 = 160
F F x 160 = 15 x 1 = 15
Sum = 431 (decimal)
Standard representation of the above hexadecimal number is 1AF H; put the letter ‘H’ at the end.
The hexadecimal system is also useful in computer works, because it’s based on power of 2.
Each digit in the hexadecimal system is equivalent to four digits in the binary system, two digits in the hexadecimal system is equivalent to eight digits (1 byte) in the binary system, and so on.
Example:
Binary value 11111010_{2} holds two hexadecimal values. One is by 1010_{2} and the other one by 1111_{2}. In hexadecimal they represent A H and F H respectively.
So, 11111010_{2} = FA H
Last edited by eranga262154; Jun 4th, 2007 at 12:20 AM.
Reason: Incomplete
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat”  Gautama Buddha

Jun 3rd, 2007, 11:38 PM
#6
Thread Starter
PowerPoster
Conversion of One Number System to Another
Now you already know that how to convert binary and hexadecimal values into decimal values. So I don’t want to discuses it again and make my tutorial so bulky and unpleasant to you.
First I’ll explain that how to convert a decimal value into binary and hexadecimal value. And then explain that how to convert a binary value into hexadecimal and vise versa.
From Decimal to Binary
Divide the given decimal number by 2, until can’t do further dividing. And at the same time writedown 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 can’t 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. It’s not difficult. Just you have to keep in mind 0000_{2} to 1111_{2} 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:
11111010_{2} = (1111 1010)_{2} = FA H
10011101_{2} = (1001 1101)_{2} = 9D H
101011_{2} = (0010 1011)_{2} = 2B H
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.
Last edited by eranga262154; Jun 4th, 2007 at 12:17 AM.
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat”  Gautama Buddha

Jun 3rd, 2007, 11:44 PM
#7
Thread Starter
PowerPoster
Decimal Numbers and their Binary and Hexadecimal Equivalents
The following table state that the decimal numbers with there equivalent binary and hexadecimal values.
Code:
Decimal Number Binary Equivalent Hexadecimal Equivalent
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F
16 00010000 10
17 00010001 11
50 00110010 32
240 11110000 F0
250 11111010 FA
255 11111111 FF
That's all about the number systems. Hope you gain a tiny. If you think that there should any changes, or suggestions please feel free to send it to me.
Thanks,
Best regard,
Eranga.
Last edited by eranga262154; Jun 4th, 2007 at 12:22 AM.
Reason: Incomplete
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat”  Gautama Buddha
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
Survey posted by VBForums.
