Bitzenbytes.com

CompuClues Forum

  User  Password
Friday, May 09, 2008 - 05:35 PM
Search
Main Menu
Who's Online
MEMBERS ONLINE

You are an anonymous user. You can register for free by clicking here
User name
Password
 Remember me
Firefox
Get Firefox 110
Languages
Preferred language:

Numbers 101
Numbers 101
Date: July 2, 2001
Author: Bob

bitzenbytes


Binary & Other Number Systems

The noumenal facts are that the title of this article existed prior to the domain name that points to the website, and the domain name of the website existed prior to your discovery of this article.  The phenomenal facts are your knowledge of the existence of the article and your estimated value of the article as it exists in your mind.

Data Data of any sort must be converted from our understanding of it to reproducible symbols. We record these symbols on media so that we can recall them at will. Some of this media we can interpret directly with our senses. We also use machines to record data. Some of these records can be interpreted directly with our senses, but some of these records must be interpreted by machines before we can understand them. We call these machines data processors. A computer is a data processor. The function of a computer is to process data electronically inside a CPU and among other components. Data comes in at least two flavors: analog and digital. Networks allow data to flow between computers; Both analog and digital signals may be employed in communicating between computers.

Analog data Analog data typically occurs in wave form. Some analog data can be interpreted by humans as sight and sound. The signals, which we send each other to communicate, are data. Sound data has as many forms as sight data but we often don't distinguish discreetly among sounds. Sound data may be transmitted as signals, speech, and music. Sight data may include letters, numbers, and other characters (handwritten or printed), as well as photos, graphics, and film. All these data are, in their nature, analog. In this form, they are unusable in a computer. A computer can only process concise, simple data formats; data such that it can be processed very effectively.

Digital data Computers, mostly, operate totally on electricity. Only electrical data can be interpreted by a computer. Some newer computers also employ discreet light. For simplicity, we will avoid light for the moment. Computers deal with data that can be encoded using electric signals. While analog computers can be built (with multiple states for a given datum object), the easiest form in which data can be encoded is as a series of semaphores that indicate one of two states for each datum object. We call these states by various names depending on the system of notation being used. Some example of the two states would be the pairs: On/Off, Up/Down, 0/1, True/False, Positive/Negative, and so forth. In a computer, these two states can be altered by a device called a switch. In a computer, the most common switch used is a device called a transistor. With transistors we can represent 0's and 1's, the two states of a unit in the binary number system. We call these units by the name, bits.

When data is manipulated and transmitted by computers, the binary code that represents the data can be encoded as either a digital signal or an analog signal, but the format of the data is still digital, still binary.

Indeed, still 0 or 1.   It will help, therefore, in understanding the computer, if you limit your knowledge of numbers, for the moment, to 0, 1, many.  The interpretation of data stored in a computer is challenging as it exists in a virtual flatland in apprehension, where often a state of 0 is assumed until a state of 1 is proven.

Bits, nibbles, and bytes Each 0 or 1, represented in a computer, is called a bit. To move information from one place to another in a computer, or between computers, we take collections of bits and transmit them over media. Bit is an abbreviation of the expression BInary digiT. The digit is called binary because the values of the units that it employs are derived from the binary number system. Collections of bits are required to represent data and symbols that are more complex than bits. There are standard collections of bits identified by the names: bit, nibble, byte, word, paragraph, segment, and so forth. Sometimes these definitions vary from computer to computer.

Bits and bytes, however, tend to remain standard from computer to computer and the data that we work with most is typically encoded in a byte. A bit is one binary digit and a byte is 8 bits. A nibble is one half of a byte. Separated into two nibbles, a high order nibble and a low order nibble, a byte can be represented as a sequential collection of two nibbles.

Number Systems The numeric encoding of data for computers can be represented in any of several number systems. The most common of these would be binary, octal, decimal, and hexadecimal. The number system with which humans are most familiar is the decimal number system (base 10.) Computers at the most basic level use the binary number system (base 2). For brevity, clarity, and quick identification, we often use the hexadecimal number system (base 16) to represent binary encoding. Most often, we find hexadecimal notation useful for identifying short codes that identify one of a possible large number of states. In our case, we will be examining and working with somewhat long strings of hexadecimal numbers that represent addresses, binary masks used for filtering, and identification codes.

Our Native Number System For our understanding, we would like to read numbers in decimal. Because decimal is the number system that we learned as children and use most often, we are most comfortable judging attributes of given numbers when those numbers are represented in decimal notation--attributes like relative size, relative nearness, relative value, and various mathematical relationships. Therefore, we feel most comfortable when we have analyzed numbers, that employ a base other than 10, as decimal numbers. It is easier for us to perform decimal math than the math required for numbers using another base.

The Nibble: half of a byte... The concept of nibble, as one half of a byte is important to this explanation because we will be using hexadecimal notation. Hexadecimal notation has a unique relationship to binary notation and the concept of a nibble will be important to rapid identification of bit patterns in a byte required for the understanding of network addressing provided as hexadecimal notation. Beyond that we will have little use for the concept of the nibble.

bit

0

1 bit

bit

1

1 bit

nibble

0110

4 bits

byte

01101011

8 bits

Definitions of bits, nibbles and bytes

The binary number system The binary number system has just two digits as compared to the decimal system which has 10 digits. The decimal system uses digits 0 through 9, the binary system only uses digits 0 and 1.

In the series of calculations below, we see how to build a decimal number based on the value of the decimal digits contained in the number. In fact, we evaluate the magnitude of each digit and then add the results together to form the decimal number. We do this all of the time, but we fail to recognize it because we have done it so often that the process seems to be "second nature" to us

Unit Place   7th 6th 5th 4th 3rd 2nd 1st
Unit Place Valuation 106 105 104 103 102 101 100
Expanded valuation
X value of unit
1000000
X 5
100000
X 2
10000
X 8
1000
X 2
100
X 3
10
X 4
1
X 9








Valued unit (magnitude) 5000000 + 200000 + 80000 + 2000 + 300+ 40 + 9 = 5,282,349


Evaluation of the decimal (base 10) number 5,282,349

Units are generally represented by a single character. The possible values for units in a base 10 system are represented by the characters, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. There is no rational reason to perform the series of conversions from base 10 to base 10, above. We are, after all, converting a number of a given base to the same base. However, it does show us the basic method for converting a number, that uses any basis, to decimal (base 10) for evaluation. We can make the same conversion from binary (base 2) to decimal (base 10) by evaluating the decimal value of binary digits in a given number. To do this we set up the same series of calculations, substituting binary digits and base 2 unit place valuation. The possible values for units in a base 2 system are 0 and 1.

Unit Place 8th 7th 6th 5th 4th 3rd 2nd 1st
Unit Place Valuation 27 26 25 24 2 3 22 21 20
Expanded valuation
X value of unit
128
X 1
64
X 0
32
X 0
16
X 1
8
X 0
4
X 1
2
X 0
1
X 1









Valued unit (magnitude) 128  + 0  + 0  + 16  + 0  + 4  + 0  + 1  = 149


Evaluation of the binary (base 2) number, 10010101, as decimal number 149

The maximum value of a 7 digit decimal number would be 9,999,999. Similarly, the maximum value for an 8 digit binary number would be 11111111. A byte holds 8 binary digits and so the maximum value for a byte would be 255, decimal. Including the 0 value, all of the possible values of a byte can be used to represent 256 states.

Unit Place 8th 7th 6th 5th 4th 3rd 2nd 1st
Unit Place Valuation 27 26 25 24 2 3 22 21 20
Expanded valuation
X value of unit
128
X 1
64
X 1
32
X 1
16
X 1
8
X 1
4
X 1
2
X 1
1
X 1









Valued unit (magnitude) 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255


Evaluation of the byte, base 2 number 11111111 as decimal number 255

A nibble holds 4 binary digits and the maximum value for a nibble would be 15, decimal. Including the 0 value, all of the possible values of a nibble can be used to represent 16 states. Evaluate a byte as a high order nibble and a low order nibble and you can define 16 instances of 16 states or 256 possible states.

Unit Place 4th 3rd 2nd 1st
Unit Place Valuation 23 22 21 20
Expanded valuation
X value of unit
8
X 1
4
X 1
2
X 1
1
X 1





Valued unit (magnitude) 8 + 4 + 2 + 1 = 15


Evaluation of the nibble, base 2 number 1111 as decimal number 15

However, most computers will not operate on a nibble as a value structure and so the number of states that can be recognized in a nibble is not useful to us. The advantage of recognizing the nibble, for us, is to use the high order and low order nibbles in a byte to represent masked binary byte values (e.g., 10010101 represented as 10010000 and 00000101, or as 144 and 5, yielding the value, 149, for the byte). Most computers will operate on a bit or a byte as a value structure. These masked values can be rewritten in hexadecimal notation, a useful exercise as it will reveal the unique relationship of hexadecimal to binary. In this case 10010000 is equivalent to 90h and 00000101 is equivalent to 05h. Add these masked values and we have 95h which converts to the decimal value of 149.

In other words, two digit hexadecimal values represent not only the precise value of a binary representation of a byte, but they also reveal the exact bit pattern of a byte by simple inspection. Variables in high level programming languages may use larger structures than bytes such as words or long words to represent very large values. Typically, these are always defined in byte sized increments. Hence, the use of hexadecimal notation to represent byte values and bit patterns and the recognition of the nibble remains useful to us as a powerful mnemonic.

In review, hexadecimal notation calls for 16 single character digits to represent possible values of a hexadecimal unit. These represent the values 0 through 15 in decimal, the exact values that we can represent with a nibble. Creating a conversion table of the numbers in all three bases shows the relationship.

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


From this table, it can be discovered that the decimal value of 14 can be represented in binary notation by the nibble, 1110, and that nibble can be represented by the hexadecimal notation, E (usually written Eh.). That is straight forward. However, there is yet another relationship we know to discover. We find that representation of the possible values of a byte, in hexadecimal notation, shows that not only does a double digit hexadecimal value represent a byte value, but that the two hexadecimal values also exactly represent the bit pattern for the high and low order nibbles of a byte.

For example, the hexadecimal number F4h converts to the decimal value of 244. 244 can be represented in binary notation by the byte having a bit pattern of 11110100. Separating the high and low order nibbles we find that 1111 has the value of Fh and 0100 has the value of 4h. Therefore we can represent the bit pattern of a byte with a double digit hexadecimal number confident that the value of the hexadecimal number is the same value represented by the binary bit pattern in the byte.

Be clear that this has nothing to do with the nibble as a value structure. Double-digit hexadecimal notation is simply a useful shorthand for preserving both the value and the bit pattern of a byte in a manner that lets both be easily reconstructed while utilizing a notation format that makes identification of specific bytes and/or bit patterns easier to locate and identify in a long listing.

These facts are not only helpful for network addresses and subnetting, but will also be useful for interpretation of frame or packet values displayed by network monitors.


AND True False
True True False
False False False
AND 1 0
1 True False
0 False False
AND 1 0
1 1 0
0 0 0

Binary truth tables - AND

1 AND 1 = 1
1 AND 0 = 0
0 AND 1 = 0
0 AND 0 = 0

   

OR True False
True True True
False True False
OR 1 0
1 True True
0 True False
OR 1 0
1 1 1
0 1 0

Binary truth tables - OR

1 OR 1 = 1
1 OR 0 = 1
0 OR 1 = 1
0 OR 0 = 0

    

XOR True False
True True False
False False True
XOR 1 0
1 True False
0 False True
XOR 1 0
1 1 0
0 0 1

Binary truth tables - XOR

1 XOR 1 = 1
1 XOR 0 = 0
0 XOR 1 = 0
0 XOR 0 = 1

  

Elementary School Stuff: If you find you need to build a binary to decimal to hex conversion table (why would you unless you drop your PDA down the stairwell?), it's pretty easy. Build it in three columns. Start at the bottom and count up from 0 to 15 decimal, then 0 to F hex, and then... ...people seem to have trouble counting in 4 digit binary. But that column of binary numbers is easy to build. Separate the column of 4 digits into four columns. Build those 4 columns from right to left and from bottom to top. The four columns will always start with 0 and always end with 1. The right most column is alternating 0's and 1's.

0101010101010101

The next column is alternating 0's and 1's in sets of two.

0011001100110011

The next column is alternating 0's and 1's in sets of 4.

0000111100001111

The last column is alternating 0's and 1's, each in a group of 8.

0000000011111111

So the four columns, laid over on the right side, would look like:

0000000011111111
0000111100001111
0011001100110011
0101010101010101

You can see the pattern...

Turn that stack up to the left and you have:

1111 - 15
1110 - 14
1101 - 13
1100 - 12
1011 - 11
1010 - 10
1001 - 9
1000 - 8
0111 - 7
0110 - 6
0101 - 5
0100 - 4
0011 - 3
0010 - 2
0001 - 1
0000 - 0

Easy. And generally more accurate, for most people, than counting sequentially in binary.


Building the byte out of the nibble table above is very easy.

Remember that using hexadecimal notation a byte can be constructed from two hex digits. This gives us 16 instances of 16 values to represent the values a byte can represent. Or 16 instances of the nibble table above.

The first 16 values that a byte can represent would be the 0000th instance of the nibble table. The next 16 values (16 through 31) would be the 0001th instance of the nibble table. The third set of 16 values (32 through 47) would be the 0010th instance of the nibble table. The fourth set of 16 values (48 through 63) would be the 0011th instance of the nibble table ...and so forth until we get to the 16th set, the 1111th instance of the nibble table.

The paragraph above, rendered to a table, looks like:

1111 1111 - 240 + 15 = 255

...

0011 1111 - 48 + 15 = 63
0011 1110 - 48 + 14 = 62
0011 1101 - 48 + 13 = 61
0011 1100 - 48 + 12 = 60
0011 1011 - 48 + 11 = 59
0011 1010 - 48 + 10 = 58
0011 1001 - 48 + 9 = 57
0011 1000 - 48 + 8 = 56
0011 0111 - 48 + 7 = 55
0011 0110 - 48 + 6 = 54
0011 0101 - 48 + 5 = 53
0011 0100 - 48 + 4 = 52
0011 0011 - 48 + 3 = 51
0011 0010 - 48 + 2 = 50
0011 0001 - 48 + 1 = 49
0011 0000 - 48 + 0 = 48

0010 1111 - 32 + 15 = 47
0010 1110 - 32 + 14 = 46
0010 1101 - 32 + 13 = 45
0010 1100 - 32 + 12 = 44
0010 1011 - 32 + 11 = 43
0010 1010 - 32 + 10 = 42
0010 1001 - 32 + 9 = 41
0010 1000 - 32 + 8 = 40
0010 0111 - 32 + 7 = 39
0010 0110 - 32 + 6 = 38
0010 0101 - 32 + 5 = 37
0010 0100 - 32 + 4 = 36
0010 0011 - 32 + 3 = 35
0010 0010 - 32 + 2 = 34
0010 0001 - 32 + 1 = 33
0010 0000 - 32 + 0 = 32

0001 1111 - 16 + 15 = 31
0001 1110 - 16 + 14 = 30
0001 1101 - 16 + 13 = 29
0001 1100 - 16 + 12 = 28
0001 1011 - 16 + 11 = 27
0001 1010 - 16 + 10 = 26
0001 1001 - 16 + 9 = 25
0001 1000 - 16 + 8 = 24
0001 0111 - 16 + 7 = 23
0001 0110 - 16 + 6 = 22
0001 0101 - 16 + 5 = 21
0001 0100 - 16 + 4 = 20
0001 0011 - 16 + 3 = 19
0001 0010 - 16 + 2 = 18
0001 0001 - 16 + 1 = 17
0001 0000 - 16 + 0 = 16

0000 1111 - 0 + 15 = 15
0000 1110 - 0 + 14 = 14
0000 1101 - 0 + 13 = 13
0000 1100 - 0 + 12 = 12
0000 1011 - 0 + 11 = 11
0000 1010 - 0 + 10 = 10
0000 1001 - 0 + 9 = 9
0000 1000 - 0 + 8 = 8
0000 0111 - 0 + 7 = 7
0000 0110 - 0 + 6 = 6
0000 0101 - 0 + 5 = 5
0000 0100 - 0 + 4 = 4
0000 0011 - 0 + 3 = 3
0000 0010 - 0 + 2 = 2
0000 0001 - 0 + 1 = 1
0000 0000 - 0 + 0 = 0

A byte is 8 binary digits is 8 bits is an octet of bits (an "octet").


Annotations in italics.
[Printer friendly page | Send to a friend]