The Numeric Systems

 

Overview of the Numeric Systems

 

Introduction

In computer programming, a variable is an area of computer memory used to (temporarily) hold a value so you can request that value when you judge it necessary and ignore it when not needed. To "reserve" that area of memory, you let your compiler or interpreter know. This is referred to as declaring the variable.

To declare a variable, you must give it a name. The name allows you and the compiler or the interpreter to refer to that particular area of the computer memory. After this declaration, an area of memory is reserved for a certain amount of space. How much space is necessary? How does the compiler figure out that space? This detail is taken care of by your supplying another piece of information called a data type. To determine the amount of space necessary, the computer deals with a numeric system.

There are three numeric systems that will be involved in your programs, with or without your intervention. The decimal system provides the counting techniques that you use everyday but that the computer is not familiar with. The hexadecimal system is an intermediary system that can allow you to know how the computer deals with numbers. The binary system is the technique the computer uses to find out (almost) everything in your program.

 

The Binary System

The real and only system that the computer recognizes is made of only two symbols 0 and 1. In effect, the computer considers a piece of information to be true or to be false; and it assigns a value accordingly. Therefore, the binary system only counts 0 and 1. To get a number, you combine these values. Examples of binary numbers are 1, 100, 1011, or 1101111011.

When reading a binary number such as 1101, you should not pronounce "One Thousand One Hundred And 1", because such a reading is not accurate. Instead, you should pronounce 1 as One and 0 as zero or o. 1101 should be pronounced One One Zero One, or One One o One.

The sequence of the symbols of the binary system depends on the number that you are trying to represent.

The Decimal  System

The numeric system that we have always used uses a set of ten symbols that are 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. Each of these symbols is called a digit. Using a combination of these digits, you can display numeric values of any kind, such as 240, 3826 or 234523. This system of representing numeric values is called the decimal system because it is based on 10 digits.

When a number starts with 0, a calculator or a computer ignores the 0. Consequently, 0248 is the same as 248; 030426 is the same as 30426.

From now on, we will represent a numeric value in the decimal system without ever starting with 0: this will reduce, if not eliminate, any confusion.

Decimal Values: 3849, 279, 917293, 39473

Non- Decimal Values: 0237, 0276382, k2783, R3273

The decimal system is said to use a base 10. This allows you to recognize and be able to read any number. Indeed, the system works in increments of 0, 10, 100, 1000, 10000, and up. In the decimal system, 0 is 0*100 (= 0*1, which is 0); 1 is 1*100 (=1*1, which is 1); 2 is 2*100 (=2*1, which is 2), and 9 is 9*100 (= 9*1, which is 9). Between 10 and 99, a number is represented by left-digit * 101 + right-digit * 101. For example, 32 = 3*101 + 2*100 = 3*10 + 2*1 = 30 + 2 = 32. In the same way, 85 = 8*101 + 5*100 = 8*10 + 5*1 = 80 + 5 = 85. Using the same logic, you can get any number in the decimal system. Examples are:

 2751  = 2*103 + 7*102 + 5*101 + 1*100

         = 2*1000 + 7*100 + 5*10 + 1

         = 2000 + 700 + 50 + 1

         = 2751

67048 = 6*104 + 7*103 + 0*102 + 4*101 + 8*100

         = 6*10000 + 7*1000 + 0*100 + 4*10 + 8*1

         = 67048

Another way you can represent this is by using the following table:

etc Add 0 to the preceding left value 1000000 100000 10000 1000 100 10 0

When these numbers get large, they become difficult to read; an example is 279174394327. To make this easier to read, we will separate each thousand fraction with a comma. Our number would become 279,174,394,327. We will do this only on paper, never in a program: the compiler would not understand the comma(s).

 

The Hexadecimal  System

The decimal system just provides one way of representing numbers. Another technique uses sixteen (16) values to represent a number: this is the hexadecimal system. Since the decimal system provides only 10 digits, we cannot make up new ones. To compensate for this, the hexadecimal system uses alphabetical characters. After counting from 0 to 9, the system adds letters until it gets 16 different values. The letters used are a, b, c, d, e, and f, or their uppercase equivalents A, B, C, D, E, and F. Therefore, the hexadecimal system counts as follows: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, and f; or 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. Once again, to produce a number, you use a combination of these sixteen symbols. Examples of hexadecimal numbers are 293, 0, df, a37, c23b34, or ffed54. At first glance, the decimal representation of 8024 and the hexadecimal representation of 8024 are the same. Also, when you see fed, is it a name of a federal agency or a hexadecimal number? Does CAB represent a taxi, a social organization, or a hexadecimal number?

Therefore, from now on, to express the difference between a decimal number and a hexadecimal one, each hexadecimal number will start with 0x or 0X. The number will be followed by a valid hexadecimal combination. The letter can be in uppercase or lowercase.

Legal Hexadecimals: 0x273, 0xfeaa, 0Xfe3, 0x35FD, 0x32F4e

Non-Hex Numbers: 0686, ffekj, 87fe6y, 312

 

Signed and Unsigned Numbers

You may have noticed that the numbers we have used so far were counting from 0, then 1, then 2, and up to any number desired, in incrementing values. Such a number that increments from 0, 1, 2, and up is qualified as positive. By convention, you do not need to let the computer or someone else know that such a number is positive: by just displaying or saying it, the number is considered positive.

In real life, there are numbers counted in decrement values. Such numbers start at -1 and move down to -2, -3, -4 etc. These numbers are qualified as negative.

When you write a number "normally", the number is positive. If you want to express the number as negative, you use the - on the left side of the number. The - symbol is called a sign. Therefore, if the number does not have the - symbol, C++ (or the compiler) considers such a number as unsigned. In C++, if you declare a variable that would represent a numeric value and you do not initialize (assign a value to) such a variable, the compiler will consider that the variable can hold either a signed or an unsigned value. If you want to let the compiler know that the variable should hold only a positive value, you will declare such a variable as unsigned.

 

Numeric Representation 

 

A Bit

The computer (or an Intel computer, or a computer that runs on an Intel microprocessor) uses the binary to represent its information. A piece of information in the computer is called a datum; and the plural is data. Sometimes, the word data is used for both singular and plural.

The computer represents data using only a 0 or 1 values. To make an illustration, let's consider that a computer uses a small box to represent such a value. This small box can have only one of two states. When the box is empty, we will give it a value of 0. When the box is full, we give it a value of 1. The box can have only one of these two values.

 

Bit

Since this box can have only one of two states, consider that you can use it to represent anything that could assume one out of two values. Examples include: True-False; Parent-Child; On-Off; Discount-NoDiscount; Male-Female; Yes-No, etc.

This technique of representing values is called The Binary system. In the computer, it uses values 0 and/or 1, which themselves are called digits. Therefore, the entity used to represent such a value is called a binary digit; in its abbreviated form, it is called a bit. The bit (binary digit) is the most fundamental representation of the computer's counting system. Although this is valid for the computer, the Intel microprocessors cannot validate a variable at this level; but eventually, you will be able to manipulate data at the bit level.

The Four-Bit Combination

The binary system provides the combination of 4 bits as the second value representation of the system:
 

To count the bits, we number them starting at 0, followed by 1, 2, and 3. The count starts with the most right bit.
 

The first bit, on the right side of the nibble, is called the Low Order bit or LO bit. The last bit, on the left side of the nibble, is called the High Order bit or HI bit. The other bits are called by their positions: bit 1 and bit 2.

Once again, each bit can have one of two states. Continuing with our illustration, when a box is empty, it receives a value of 0. Otherwise, it has a value of 1. On a group of four consecutive bits, we can have to following combinations:
 


 

This produces the following binary combinations: 0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111 = 16 combinations. When using the decimal system, these combinations can be resented as 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, and 15.

As you can see, a nibble is represented by a group of 4 bits. This is also a system that the computer uses to count bits internally. Sometimes, in your program in the help files, you will encounter a number less than four bits, such as 10 or 01 or 101. How do you reconcile such a number to a nibble? The technique used to complete and fill out the nibble consists of displaying 0 for each non-represented bit; this makes it easier to recognize. The binary number 10 will be the same as 0010. The number 01 is the same as 0001. The number 101 is the same as 0101. This technique is valuable and allows you to always identify a binary number as a divisor of 4.

When all bits in a nibble are 0, you have the lowest value you can get, which is 0000. Any of the other combinations has at least one 0 bit, except for the last one. When all bits are 1, this provides the highest value possible for a nibble. The lowest value, also considered the minimum value, can be represented in the decimal system as 0. The highest value, also considered the maximum, can be expressed in decimal value as 24 (2 represents the fact that there are two possible states: 0 and 1; 4 represents the fact that there are four possible combinations), which is 16.

As you can see, the binary system is very difficult to read when a value combines various bit representations. To make your life a little easier, the computer recognizes the hexadecimal representation of bits. Following the box combinations above, we can represent each 4-bit of the sixteen combinations using the decimal, hexadecimal, and binary systems as follows:

Decimal Hexadecimal Binary
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
10 a 1010
11 b 1011
12 c 1100
13 d 1101
14 e 1110
15 f 1111
 
Table of numeric conversions
 

When looking at a binary value represented by 4 bits, you can get its decimal or hexadecimal values by referring to the table above. For this reason, you may have to memorize it.

A nibble, which is a group of four consecutive bits, has a minimum and maximum values on each system:
 

  Decimal Hexadecimal Binary
Minimum 0 0x0 0000
Maximum 15 0xf 1111

Practical Learning: Examining the Binary System

  1. To launch the calculator, from the task bar, click Start -> Programs -> Accessories -> Calculator (if the Calculator application is not installed in your computer, you should install it; you will need on a regular basis)
  2. On the main menu of the Calculator application, click View -> Scientific:
     

     
  3. Click the Bin radio button.
    Notice that on the numeric buttons, only the 1 and the 0 buttons are enabled.
  4. Click 7, 5, and 9. Nothing happens.
  5. Click 1
  6. Click Dec, then click Hex. Notice that all three systems display 1.
  7. Click Bin to access the binary system
  8. Click 1 then 0 to display 10
  9. Click Hex. Notice, that the calculator displays 2.
  10. Click Dec
  11. Using your keyboard, type 15
  12. Click Bin and notice the displayed number: 1111.
  13. Click Hex and notice the displayed number: F. For our programming purposes, we would write this number as 0XF
  14. Type 0
  15. Click Bin.

A Byte

Byte

A byte combines 8 consecutive bits. Once again, the bits are counted from left to right starting at 0. The most right bit is called the Low Order bit or LO bit. The most left bit is called the High Order bit or HI bit. The other bits are refereed to following their positions. A byte is considered as being made of two nibbles. The right nibble, made of the right 4 bits, is called the Low Order nibble or LO nibble. The left nibble, made of the left 4 bits, is called the High Order nibble or HI nibble.
 

The Parts of a Byte

Using the binary system, you can represent the byte using a combination of 0s and 1s. When all bits have a value of 0, the byte is represented as 00000000. On the other hand, when all bits have a value of 1, the byte is represented as 11111111. When the number grows very large, it becomes difficult to read. Therefore, we will represent bits in groups of four. Instead of writing 00000000, we will write 0000 0000. This makes the number easier to read.
 

If you get the patience to create combinations of bits using the boxes as we did for the nibble, you would find out that there are 256 possible combinations. Another way to find it out is by using the base 2 technique:

    27  + 26 + 25 + 24 + 23 + 22 + 21 + 20

= 128 + 64 + 32 + 16 + 8  + 4   + 2  + 1

= 256

Therefore, the maximum decimal value you can store in a byte is 256.

When a byte is completely represented with 0s, it provides the minimum value it can hold; this is 0000 0000, which is also 0. When all bits have a value of 1, which is 1111 1111, a byte holds its maximum value that we calculated as 255. As done with the nibble, we get the following table:
 

  Decimal Hexadecimal Binary
Minimum 0 0x0 0000 0000
Maximum 255 0xff 1111 1111

A Word

A word is a group of 16 consecutive bits. Again, the bits are counted from left to right starting at 0:

Considered as a group of 16-bit, the most right bit of a word is called the Low Order bit or LO bit. The most left bit is called the High Order bit or HI bit. The other bits are referred to using their positions.: bit 1, bit 2, bit 10, etc.

When considered as a group of four nibbles, the group of the most right 4-bits is called the Low Order nibble. The group of the most left 4-bits is called the High Order nibble. The other nibbles are referred to using their positions: nibble 1 and nibble 2.
If you consider that a word is made of two bytes, the group of the right 8 bits is called the Low Order byte. The other group is called the High Order byte.

The most fundamental representation of a word in binary format is 0000000000000000. To make it easier to read, you can group bits in 4, like this 0000 0000 0000 0000. Therefore, the minimum binary value represented by a word is 0000 0000 0000 0000. The maximum binary value represented by a word is 1111 1111 1111 1111.

The minimum decimal value of a word is 0. To find out the maximum decimal value of a word, you can use the base 2 formula, filling out each bit (with 1):

    1*215+ 1*214  +1*213 + 1*212 + 1*211 + 1*210 + 1*29 + 1*28 + 1*27 + 1*26 + 1*25 + 1*24 + 1*23 + 1*22 + 1*21 + 20 

= 32768 + 16384 + 8192  + 4096  + 2048   + 1024  + 512   + 256  + 128   + 64    + 32    + 16     + 8     + 4      + 2      + 1

= 65535

The minimum hexadecimal value you can store in a word is 0x0000000000000000. This is also represented as 0x00000000, or 0x0000, or 0x0. All these numbers produce the same value. To find out the maximum hexadecimal number you can represent with a word, replace every group of 4-bits with an f or F:

1111111111111111
1111 1111 1111 1111
f f f f
= 0xffff
= 0Xffff
= 0xFFFF
= 0XFFFF

Counting on base and extending the table we used earlier, we would get:

 

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
215 + 214 + 213 + 212 + 211 + 210 + 29 + 28 + 27 + 26 + 25 + 24 + 23 + 22 + 21 + 20
32768 + 16384 + 8192 + 4096 + 2048 + 1024 + 512 + 256 + 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1
= 65535

A Double-Word

A double-word is a group of two consecutive Words. This means a double-word combines 4 bytes, 8 nibbles or 32 bits. The bits, counted from left to right start at 0 and end at 31.

The most right bit, bit 0, is called the Low Order bit, or LO bit. The most left bit, bit 31, is called the High Order bit, or HI bit. The other bits are called using their positions.

The group of the 4 right bits is called the Low Order nibble, or LO nibble. The group of the 4 left bits is called the High Order nibble, or HI nibble. You use their positions when referring to the other nibbles.

The group of the first 8 bits (from bit 0 to bit 7), which is the right byte, is called the Low Order Byte, or LO Byte. The group of the last 8 bits (from bit 24 to bit 31), which is the left byte, is called the High Order Byte, or HI Byte. The other bytes are called by their positions.

The group of the right 16 bits, or the right Word, is called the Low Order Word, or LO Word. The group of the left 16 bits, or the left Word, is called the High Order Word, or HI Word.

The minimum decimal value of a double-word is 0. To find out the maximum decimal value of a word, you can use the base 2 formula giving a 1 value to each bit:

1*231 + 1*230 + 1*229 + 1*228 + 1*227 + 1*226 + 1*225 + 1*224 + 1*223 + 1*222 + 1*221 + 1*220  

+ 1*219 + 1*218 + 1*217 + 1*216 + 1*215 + 1*214 + 1*213 + 1*212 + 1*211 + 1*210 + 1*29 + 1*28 + 1*27

+ 1*26 + 1*25 + 1*24 + 1*23 + 1*22 + 1*21 + 20 

= 2,147,483,648 + 1,073,741,824 + 536,870,912 + 268,435,456 + 134,217,728 + 67,108,864 + 33,554,432

+ 16,777,216 + 8,388,608 + 4,194,304 + 2,097,152 + 1,048,576 + 524,288 + 262,144 + 131,072 + 65,536

+ 32,768 + 16,384 + 8,192 + 4,096 + 2,048 + 1,024 + 512 + 256 + 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1

= 4,294,967,295

The minimum hexadecimal value you can store in a word is 0x0. To find out the maximum hexadecimal number you can represent with a word, replace every group of 4-bits with an f or F:
 

1111 1111 1111 1111 1111 1111 1111 1111
f f f f f f f f
= 0xffffffff = 0XFFFFFFFF
 

Conversion from Decimal to Binary

 

Converting a Byte From Decimal to Binary

Remember that the maximum decimal number you can store in a byte is 255. Once you have a decimal number, you can use the remainder operation to fill out the bits. Let's convert the number 206.

Considering 206, find out the range of the number. Since this is greater than 128, fill out bit 7 with 1. This produces:

128 64 32 16 8 4 2 1
1              
 

Next, find the remainder of 206 by 128. This is 206 / 128 = Remainder(78). In C++, this operation would be 206 % 128 = 78. The result, 78, is greater than 64. therefore, fill out the corresponding bit of 64, which is bit 6, with 1:

128 64 32 16 8 4 2 1
1 1            
 

Next, find the remainder of 78 by 64. 78 / 64 = Remainder(14). This is equivalent in C++ to 78 % 64 = 14. 14 is less than 32. Therefore, the bit corresponding to decimal 32, which is bit 5, has a binary value of 0. 14 is less than 16. Therefore, bit 4 is 0. 14 is greater than 8. Therefore, fill out bit 3 with 1:

128 64 32 16 8 4 2 1
1 1 0 0 1      
 

Now, find the remainder of  14 by 8. 14 % 8 = 6. 6 is greater than 4. Therefore, bit 2 has a binary value of 1.

128 64 32 16 8 4 2 1
1 1 0 0 1 1    
 

Find the remainder of 6 by 4: 6 % 4 = 2. According to this, bit 1 will have a binary value of 1. The remaining decimal value is 0. Therefore, bit 0 has a value of 0. The decimal number 206 produces the following table:

  128 64 32 16 8 4 2 1
  1 1 0 0 1 1 1 0
 
= 1 1 0 0 1 1 1 0
    = 11001110
    = 1100 1110

                     

Converting any Number From Decimal to Binary

Converting a decimal number to binary takes longer because of the various comparisons you would perform. There are, as always, various techniques available. Once again, find the range of the number using numbers such as those:

2n-1 230 229 228 227 226 225 224
etc 1,073,741,824 536,870,912 268,435,456 134,217,728 67,108,864 33,554,432 16,777,216
 
223 222 221 220 219 218 217 216
8,388,608 4,194,304 2,097,152 1,048,576 524,288 262,144 131,072 65,536
 
215 214 213 212 211 210 29 28
32,768 16,384 8,192 4,096 2,048 1,024 512 256
 
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1

Imagine you would like to convert the following decimal number 408340623 = 408,340,623 to binary. (I picked this number completely randomly)

408,340,623 is less than 536,870,912 but is greater than 268,435,456. Therefore, we will start the counting at 268,435,456. Write 1 under 268,435,456.

    536,870,912 268,435,456 134,217,728 67,108,864 33,554,432 16,777,216
    0 1        

At this time, we have the number as 1

Next, find the remainder of 408,340,623 by 268,435,456, which is 139,905,167. 139,905,167 is greater than 134,217,728. Therefore, write 1 under 134,217,728

    536,870,912 268,435,456 134,217,728 67,108,864 33,554,432 16,777,216
    0 1 1      

The current number is 11000 or 1 1000

Now, find the remainder of 139,905,167 by 134,217,728. This is 5,687,439. This number is between 8,388,608 and 4,194,304. Therefore, fill each bit to 0 down to 4,194,304:

    536,870,912 268,435,456 134,217,728 67,108,864 33,554,432 16,777,216
    0 1 1 0 0 0
 
8,388,608 4,194,304 2,097,152 1,048,576 524,288 262,144 131,072 65,536
0              

Since 4,194,304 is immediately less than 5,687,439 fill it with 1

    536,870,912 268,435,456 134,217,728 67,108,864 33,554,432 16,777,216
    0 1 1 0 0 0
 
8,388,608 4,194,304 2,097,152 1,048,576 524,288 262,144 131,072 65,536
0 1            

The number becomes 1100001 or 110 0001

Then find the remainder of 5,687,439 by 4,194,304. This produces 1,493,135. This number is greater than 1,048,576. Therefore, write 0 under 2,097,152 and 1 under 1,048,576.

    536,870,912 268,435,456 134,217,728 67,108,864 33,554,432 16,777,216
    0 1 1 0 0 0
 
8,388,608 4,194,304 2,097,152 1,048,576 524,288 262,144 131,072 65,536
0 1 0 1        

Now the number is 110000101 or 1 1000 0101

Find the remainder of 1,493,135 by 1,048,576. The result is 444,559. The next number greater than 444,559 is 262,144. Therefore, fill it with 1 and fill out the 524,288 field with 0:

    536,870,912 268,435,456 134,217,728 67,108,864 33,554,432 16,777,216
    0 1 1 0 0 0
 
8,388,608 4,194,304 2,097,152 1,048,576 524,288 262,144 131,072 65,536
0 1 0 1 0 1    

The number has become 11000010101 or 110 0001 0101

Find the remainder of 444,559 by 262,144. This is 182415. This number is greater than 131,072. Therefore, fill out the corresponding bit with 1.

    536,870,912 268,435,456 134,217,728 67,108,864 33,554,432 16,777,216
    0 1 1 0 0 0
 
8,388,608 4,194,304 2,097,152 1,048,576 524,288 262,144 131,072 65,536
0 1 0 1 0 1 1  

The current number is 110000101011 or 1100 0010 1011

The remainder of 182,415 by 131,072 is 51,343 which is less than 65,536 but greater than 32,768. For this reason, the equivalent bit of 65,536 is 0 and that of 32,768 is 1:

    536,870,912 268,435,456 134,217,728 67,108,864 33,554,432 16,777,216
    0 1 1 0 0 0
 
8,388,608 4,194,304 2,097,152 1,048,576 524,288 262,144 131,072 65,536
0 1 0 1 0 1 1 0
 
32,768 16,384 8,192 4,096 2,048 1,024 512 256
1              

The current number is 11000010101101 or 11 0000 1010 1101

The remainder of 51,343 by 32,768 is 18,575. This number is between 32,768 to 16,384. This results in:

    536,870,912 268,435,456 134,217,728 67,108,864 33,554,432 16,777,216
    0 1 1 0 0 0
 
8,388,608 4,194,304 2,097,152 1,048,576 524,288 262,144 131,072 65,536
0 1 0 1 0 1 1 0
 
32,768 16,384 8,192 4,096 2,048 1,024 512 256
1 1            

The number becomes 110000101011011 or 110 0001 0101 1011

The remainder of 18,575 by 16,384 is 2191. This number is greater that 2048. Therefore, the binary equivalents of both the 8,192 and the 4,096 bits is 0. The bit equivalent of 2,048 is 1:

    536,870,912 268,435,456 134,217,728 67,108,864 33,554,432 16,777,216
    0 1 1 0 0 0
 
8,388,608 4,194,304 2,097,152 1,048,576 524,288 262,144 131,072 65,536
0 1 0 1 0 1 1 0
 
32,768 16,384 8,192 4,096 2,048 1,024 512 256
1 1 0 0 1      

The number becomes 110000101011011001 or 11 0000 1010 1101 1001

The remainder of 2,191 by 2,048 is 143. The next number lower than 143 is 128. The resulting tables are:

    536,870,912 268,435,456 134,217,728 67,108,864 33,554,432 16,777,216
    0 1 1 0 0 0
 
8,388,608 4,194,304 2,097,152 1,048,576 524,288 262,144 131,072 65,536
0 1 0 1 0 1 1 0
 
32,768 16,384 8,192 4,096 2,048 1,024 512 256
1 1 0 0 1 0 0 0
 
128 64 32 16 8 4 2 1
1              

The current number is 1100001010110110010001 or 11 0000 1010 1101 1001 0001

Find the remainder of 143 by 128. This produces 15; a number that is greater than 8 but less than 16. The bits of 64, 32, and 16 will receive a bit value of 0. Bit 8 will have a value of 1:

    536,870,912 268,435,456 134,217,728 67,108,864 33,554,432 16,777,216
    0 1 1 0 0 0
 
8,388,608 4,194,304 2,097,152 1,048,576 524,288 262,144 131,072 65,536
0 1 0 1 0 1 1 0
 
32,768 16,384 8,192 4,096 2,048 1,024 512 256
1 1 0 0 1 0 0 0
 
128 64 32 16 8 4 2 1
1 0 0 0 1      

The current number is:

11000010101101100100010001 or 11 0000 1010 1101 1001 0001 0001

The remainder of 15 by 8 is 7, which is greater than 4. Fill out bit 2 with 1.

    536,870,912 268,435,456 134,217,728 67,108,864 33,554,432 16,777,216
    0 1 1 0 0 0
 
8,388,608 4,194,304 2,097,152 1,048,576 524,288 262,144 131,072 65,536
0 1 0 1 0 1 1 0
 
32,768 16,384 8,192 4,096 2,048 1,024 512 256
1 1 0 0 1 0 0 0
 
128 64 32 16 8 4 2 1
1 0 0 0 1 1    

The current number is:

110000101011011001000100011 or 110 0001 0101 1011 0010 0010 0011

The remainder of 7 by 4 is 3, which is greater than 2. This produces:

    536,870,912 268,435,456 134,217,728 67,108,864 33,554,432 16,777,216
    0 1 1 0 0 0
 
8,388,608 4,194,304 2,097,152 1,048,576 524,288 262,144 131,072 65,536
0 1 0 1 0 1 1 0
 
32,768 16,384 8,192 4,096 2,048 1,024 512 256
1 1 0 0 1 0 0 0
 
128 64 32 16 8 4 2 1
1 0 0 0 1 1 1  

The current number is:
1100001010110110010001000111 or 1100 0010 1011 0110 0100 0100 0111

The remainder of 3 by 2 is 1. This means that you will fill out bit 0 with 1:

    536,870,912 268,435,456 134,217,728 67,108,864 33,554,432 16,777,216
    0 1 1 0 0 0
 
8,388,608 4,194,304 2,097,152 1,048,576 524,288 262,144 131,072 65,536
0 1 0 1 0 1 1 0
 
32,768 16,384 8,192 4,096 2,048 1,024 512 256
1 1 0 0 1 0 0 0
 
128 64 32 16 8 4 2 1
1 0 0 0 1 1 1 1

The final number is:
11000010101101100100010001111 or 1 1000 0101 0110 1100 1000 1000 1111

The equivalent decimal number of 408340623 in binary is 11000010101101100100010001111 or 1 1000 0101 0110 1100 1000 1000 1111

This number can easily be converted from binary to hexadecimal using the table of numeric conversions:

 
0001 1000 0101 0110 1100 1000 1000 1111
1 8 5 6 C 8 8 F
= 0x1856C88F
 

Conversion from Binary to Decimal

 

Converting a Byte From Binary To Decimal

Since the bits are numbered from right to left , you can calculate the decimal value of a byte using the base 2. Consider a binary number intensely mixed with 0s and 1s such as 11010111. The 11010111 can be calculated as:

1 1 0 1 0 1 1 1
= 1*27 + 1*26 + 0*25 + 1*24 + 0*23 + 1*22 + 1*21 + 1*20
= 1*128 + 1*64 + 0*32 + 1*16 + 0*8 + 1*4 + 1*2 + 1*1
= 215

An alternative to calculating such a number is by using the following table:

128 64 32 16 8 4 2 1
               
 
Decimal to Binary Conversion Table
 

When you are presented with a binary number, you can just write the corresponding bit value under the ranking decimal number. Consider that you want to calculate the decimal equivalent of the 01110110 binary number. Using the last table, you can perform the operation like this:

128 64 32 16 8 4 2 1
0 1 1 1 0 1 1 0

This produces:

0 64 32 16 0 4 2 0
 
= 64 + 32 + 16 + 4 + 2
 
= 118
 

Using any of these techniques, you can find out the value of a combination of any 8 consecutive bits.

When all bits are 0, the byte also has a value of 0. When combining and mixing 0 and 1 bits, you can get binary values as varied as possible: 0101 0010 or 1101 1110 or 0111 1100. We only need to know what each combination would represent. Considerer another binary number such as 11001000. To convert it to the decimal system, we use the decimal to binary table conversion to get:

128 64 32 16 8 4 2 1
1 1 0 0 1 0 0 0

= 128 + 64 + 0 + 0 + 8 + 0 + 0 + 0 = 128 + 64 + 8 = 200
 
 

Converting any Number From Binary To Decimal

Once you are presented with a binary number, you can produce or use a table inspired from the binary to decimal conversion table:

Etc 214 213 212 211 210 29 28 27 26 25 24 23 22 21 20
Etc 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1

Imagine you would like to convert the 10011110011101101 binary number to a decimal value.

1 0 0 1 1 1 1 0 0 1 1 1 0 1 1 0 1
65536 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1

= 65536 + 0  +   0  +8192+4096+2048+1024+  0 +   0 + 128+ 64 +32  + 0   +  8  +  4  +  0  + 1

= 65536 +               8192+4096+2048+1024      +         128+ 64 +32     +      8   + 4      +     1

= 81133

 

Conversion from Decimal to Hexadecimal

 

Converting a Byte From Decimal to Hexadecimal

To convert a decimal value of a byte to its hexadecimal equivalent, again keep in mind that the maximum number you are dealing with is 255 (this is because the operation will be a little different later on). Find the remainder of the decimal number by 16. This remainder will constitute the low nibble. The result will constitute the high nibble. Therefore, use the table of numeric conversions to find the equivalent hexadecimal number for each nibble.

Let's convert decimal 225 to hexadecimal. The remainder of 225 by 16 is 225 % 16 = 1 and the natural result is 14. Using the table of numeric conversions, decimal 14 = hexadecimal E. Decimal 1 = hexadecimal 1. Therefore, the decimal number 225 has a hexadecimal value of 0XE1.

As another example, Let's convert the decimal 203 to the hexadecimal system. 203 % 16 = 11 and the natural result is 12. Using the table of numeric conversions, decimal 12 = hexadecimal C; decimal 11 = hexadecimal B. Therefore, decimal 203 = hexadecimal 0XCB

 

Converting any Number From Decimal to Hexadecimal

To convert any number from decimal to hexadecimal, find the remainder of the number by 16. This remainder would be the LO nibble. Use the quotient to find the remainder by 16; this remainder would be the second nibble. Continue until the decimal is less than 16.

Consider a decimal number such as 1325 to convert to hexadecimal. The remainder of 1325 by 16 is

1325 % 16 = 13 and the quotient is 82. Therefore the left number will be 13.

82 % 16 = 2 and the quotient is 5. Therefore, the second number from left is 2; this would produce 2 and 13.

Since the quotient, 5, is less that 16, it will be put to the left of the existing numbers. We get 5 | 2 | 13. According to the table of numeric conversions, decimal 13 = hexadecimal D. Therefore, decimal 1325 = hexadecimal 0x52D

Let’s convert decimal 462834 to hexadecimal:

462834 % 16 = 2 and the quotient is  28927
28927 % 16 = 15 and the quotient is 1807
1807 % 16 = 15 and the quotient is 112
112  % 16 = 0 and the quotient is 7


The different nibbles (combination of 4 bits) of this number are 7 | 0 | 15 | 15 | 2. According to the table of numeric conversions, decimal 15 = hexadecimal F. The number is 7 | 0 | F | F | 2. Therefore, the hexadecimal equivalent of the decimal number 462834 is 0x70FF2

 

Conversion from Hexadecimal to Decimal

 

Converting a Byte From Hexadecimal to Decimal

A byte is made of 8 bits. This means that the highest hexadecimal value you can represent with a byte is 0xFF and the highest decimal value is 255. To convert a hexadecimal number to decimal, multiply each hexadecimal digit to its 16 base value. Starting on the left side, which is the low order bit, use the following table:

161 160
   

Consider a hexadecimal byte represented with 0x24, to convert it to decimal, you would use:

    2 * 161 + 4 * 160 

= (2 * 16) + (4 * 1)

= 32 + 4

= 36

Therefore, the decimal equivalent of 0x24 is 36

Consider another hexadecimal number as 0x5D. To convert it to decimal, you would write:

5 * 161 + D * 160. If you look at the table of numeric conversions,

Decimal Hexadecimal Binary
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
10 A 1010
11 B 1011
12 C 1100
13 D 1101
14 E 1110
15 F 1111
 
Table of numeric conversions
 

you would see that the decimal value of hexadecimal D is 13. Therefore, the conversion would be performed as follows:

    5 * 161 +   D * 160 

=  5 * 161 +  13 * 160 

= (5 * 16) + (13 * 1)

= 80 + 13

= 93

Therefore, hexadecimal 0x5D = decimal 93

 

Converting any Number From Hexadecimal to Decimal

To convert a hexadecimal number to decimal, multiply each digit of the hexadecimal number to its 16-base equivalent. Starting from the 

etc 166 165 164 163 162 161 160

Consider a hexadecimal number such as 0x80329. To convert it to decimal, you would write:

    8 * 164 + 0 * 163 + 3 * 162 + 2 * 161 + 9 * 160 

= (8 * 65536) + (0 * 4096) + (3 * 256) + (2 * 16) + (9 * 1)

=    524288    +       0        +     768     +    32      +     9

=    525097

Therefore, hexadecimal 0x80329 = decimal 525097

Consider another hexadecimal number such as 0xBE45A6. To convert it to decimal, using the base 16, you would write an equation as:

B * 165 + E * 164 + 4 * 163 + 5 * 162 + A * 161 + 6 * 160

Referring to the table of numeric conversions, you would find out that the decimal equivalent of hexadecimal B is 11, that of E is 14, and that of A is 10. Therefore, you would rewrite the equation as:

    11 * 165          +  14 * 164     +   4 * 163    +  5 * 162  +  10 * 161 +  6 * 160

= (11 * 1048576 ) + (14 * 65536) + (4 * 4096) + (5 * 256) + (10 * 16) + (6 * 1)

= 11534336          +     917504     +    16384    +    1280     +    160     +  6

= 12469670

= 12,469,670

Therefore, hexadecimal 0xBE45A6 = decimal 12469670 or 12,469,670

 

Conversion from Binary to Hexadecimal

 

Converting a Byte From Binary to Hexadecimal

When all bits are 0, the byte also has a value of 0. When combining and mixing 0 and 1 bits, you can get binary values as varied as possible: 0101 0010 or 1101 1110 or 0111 1100. We only need to know what each combination would represent. If you divide bits by groups of four, you can use the table of numeric conversions to find out what each group represents. Consider a binary number such as 10101101. Dividing it in groups of 4-bits, we get 1010 1101. Referring to our conversion table, the low order nibble has a hexadecimal value of 8. The high order nibble has a hexadecimal value of C.

 

1010 1101
A D

Therefore, the binary number 10101101 has a hexadecimal representation of 0XAD.

Of course, the binary number 10101101 is equivalent to 128 + 0 + 32 + 0 + 8 + 4 + 0 + 1 = 173 in the decimal system

Converting any Number From Binary to Hexadecimal

To convert a binary number to hexadecimal, use the table of numeric conversions. First, convert the number in groups of 4 bits. If the most left group has less than 4 bits, complete the other bits with 0 each.

Imagine you would like to convert the 100011111111011011100 binary to its hexadecimal equivalent. First create groups of 4 bits. The number becomes:

11 0001 1111 1110 1101 1100

Since the most left group has only 2 bits, you can add two 0 bits to its left to make it a group of 4. The number becomes:

0011 0001 1111 1110 1101 1100

Using the table of numeric conversions, you get:

0011 0001 1111 1110 1101 1100
  3      1      F      E      D     C
= 0x31FEDC

 

Conversion from Hexadecimal to Binary

 

Converting a Byte From Hexadecimal to Binary

The conversion of a hexadecimal number to its binary equivalent is extremely easy. The only thing you need is the table of numeric conversions. A byte is represented with two hexadecimal symbols. The right symbol represents the low nibble (the first 4 bits). The other symbol is the high nibble.

Consider a hexadecimal number such as 0X26. Referring to our table of numeric conversions, 2 has a binary representation of 0010; hexadecimal 6 is represented in binary as 0110. Therefore, the hexadecimal number 0X26 can be represented in binary as 00100110 which is easily read as 0010 0110. Remember that when a number has leading 0s, the computer ignores the 0(s). As a result, the computer would display 00100110 as 100110

Let's convert the hexadecimal 0XD5 to binary. The binary representation of D is 1101. The binary representation of 5 is 0101. Therefore, hexadecimal 0XD5 is represented in binary as 11010101 or 1101 0101

Converting any Number From Hexadecimal to Binary

To convert any hexadecimal number to binary, once again, you use the table of numeric conversion. Each hexadecimal digit will be converted to its binary equivalent.

Consider you would like to convert the hexadecimal number 0x72FA to binary. Using the table of numeric conversions:

7 = 0111
2 = 0010
F = 1111
A = 1010

Therefore, hexadecimal 0x72FA is represented in binary as 011100101111010. This can be read as 0111 0010 1111 1010. The computer would display it as 11100101111010

 

Copyright © 2003-2012 FunctionX