Computer Science Theory
Last Updated on Wednesday, 18 November 2009 04:05 Written by Administrator Sunday, 21 June 2009 21:18
Computer Science – Theory – 101 - By: Jason Peter Sage
Seriously, this page is a brief guide to what binary, decimal, and hexadecimal notation are and how they relate to computers. Mostly, this document is meant to be a quick reference more than anything else.
This text file is a reference to some facts about binary, decimal, and hexadecimal numeric notation as it pertains to computers.
BIT - The smallest unit a computer can measure; its value is always on or off, zero or one, true or false. True USUALLY is a one, but I have seen some computer systems actually do the inverse. TYPICALLY = ZERO = FALSE and ONE = TRUE
NYBBLE - A succession of four BITS. Nybbles are sometimes referred to or used to explain a value in “four bit chunks”. Usually, they are used because they are easier to understand then a BYTE for the simple fact that they represent less information. In fact, in hexadecimal notation, a nybble can be represented by ONE DIGIT! Yes, a nibble can have 16 possible values ranging from 0 - 15. Likewise, a single digit in hexadecimal has the same numeric range, 0 – 15. So what’s easier to read? This: 0101 or: 5 How do you know the 5 is a hexadecimal 5 and not a decimal? Well, for a value like five it’s the same either way, but you want to indicate what number system you are using:
“d” - Decimal – Base 10 – (You use these every day, typically the assumed numbering system, not necessary to notate usually.
“&h” or “$” - Hexadecimal - Base 16 – Range 0 – F or d0 – d15 (decimal zero to fifteen)
“b” - Binary – Base 2 – Same notation whether you are representing a bit, a nibble, a byte, a word, a double word, or a quadword. These are fancy terms that describe how big (range numerically, and memory locations) the number is in relation to the computer.
BYTE - Eight BITS make up a byte. 2 Nybbles make up a BYTE also (Because a Nybble is four bits, so 2 Nybbles give ya eight bits, hence one byte.) A byte is often referred to as the smallest data type, or unit, one can store in the computer. For example: one “K” of memory (A “K” is usually a 1000, but in computer jibberish, its 1024) has 1024 BYTES. (That’s 1024 * 8 bits if you do the math… that’s a lot of light switches!) A Megabyte, is actually 1024 * 1K or 1024 * 1024 bytes. Note: In laymen terms, a mega is a million bytes. In computer geek terms, a mega-byte is actually: 1048576 bytes. (1024 * 1024) Don’t ask me what a gig is, I’m very tired.
WORD - Two consecutive Bytes, it is 16 bits “WIDE”
DOUBLEWORD - Four consecutive bytes, it is 32 bits “WIDE”
QUADWORD - Eight consecutive bytes, it is 64 bits “WIDE”
BADWORD - Something you should never call your other half unless you are ready for some trouble.
Simple Binary to Dec to Hex Conversion Table
| Binary | Decimal | Hexadecimal |
| 0000 | 0 | 0 |
| 0001 | 1 | 1 |
| 0010 | 2 | 2 |
| 0011 | 3 | 3 |
| 0100 | 4 | 4 |
| 0101 | 5 | 5 |
| 0110 | 6 | 6 |
| 0111 | 7 | 7 |
| 1000 | 8 | 8 |
| 1001 | 9 | 9 |
| 1010 | 10 | A |
| 1011 | 11 | B |
| 1100 | 12 | C |
| 1101 | 13 | D |
| 1110 | 14 | E |
| 1111 | 15 | F |
OK, fine, I can count to 15 in binary, decimal, or hexadecimal. Big deal, what about all that WORD and DOUBLE WORD business?
Well, lets start with a BYTE. How do you convert a binary number to decimal without the chart?
Well, you have to look at the chart first to understand what’s next. In binary, each bit represents a ZERO or ONE. So, to represent bigger numbers, you use multiple bits. So, starting from the RIGHT side of the number, you need to know the “VALUE” each bit represents. It’s not as hard as it sounds, I’m quite daft and I understand it. Watch, because binary is 2’s compliment, I choose to call it the “multiply everything by 2 and compliment me later if you like” numbering system.
From the right, and working left, each digit in binary represents the previous bit’s value multiplied by 2.
| Decimal Value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| Bit Position | Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 |
(Why do they call bit0 bit0 when it’s the FIRST bit, I don’t know, but remember that, it may come up)
So, to convert a BINARY representation of a BYTE to its decimal value, for example: b01011101 you do the following:
1st, make a little chart like I did above but replace the bit position data with the binary number:
| Decimal Values of Bits | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| Your Binary Number | 0 | 1 | 0 | 1 | 1 | 1 | 0 | 1 |
OK, the first row contains the VALUES the corresponding BITS represent. So to get the DECIMAL value of the binary number: b01011101 you add the corresponding values together: 64 +
16 + 8 + 4 + 1 = d93 (93 in decimal)
Ok, how do I represent that binary number in hexadecimal? Ahhh…. This is where nybbles come in!
Remember how a nibble is four bits wide? And how a Nybble can be represented by one hexadecimal “digit”? Well, you split the binary BYTE (8 bits) into TWO nybbles and then use the first conversion chart I have in this document to convert the binary to hexadecimal. Only after you do this, and then take a hexadecimal number like $FE to its binary equivalent, will you appreciate the conversion chart.
OK, lets do this. The following table has the same binary number we have been working with and has it broken down into two parts. Leftmost and right most nybbles for sake of discussion.
Left Bit3 Left Bit2 Left Bit1 Left Bit0 Right Bit3 Right Bit2 Right Bit1 Right Bit0
0 1 0 1 1 1 0 1
Ok, the left nyble is: b0101, so look on the chart, what is a binary value of b0101 equal to in decimal? More importantly for this discussion, in hexadecimal? Make sure you understand it is the number $5.
Ok, now lets look at the right nibble of our byte: b1101, it’s a dec13, and a $D in hex. So, our hexadecimal representation for the binary number: b01011101 is still d93 (decimal) and $5D in hexadecimal.
Now, if you remember how each digit in binary represents a value, and these values are calculating by starting on the right, with the first binary digit (on the right) being equal to ONE, and multiplying that by 2 to get the next value, and again, and so forth, you can figure out how to make a chart that can help you translate binary numbers of any length to there decimal equivalents.
The Caveat…. What if you have two bytes that make up a word, and you already KNOW the value of the left most byte in decimal, and the right most byte in dec. (Each having a value between 0-255 … the maximum range of a single byte)? Can I use those two byte values to calculate the value of the “WORD”?
Yes, take the left most byte and multiply it by 256, then add the first byte to the result. Binary is a base2 numbering, octal is base8, decimal is base 10, hexadecimal is base 16, a BYTE is base 256!!!!!
If this last part threw ya, don’t sweat it. The more you work with computers, the more likely you may have a situation where you need to revisit this. You’ll get it then. BUT, if you do not get it even then…. Do what I do, use your Microsoft calculator, put it in scientific mode, and use it to convert to and from decimal, hexadecimal, and binary. After all, I told you I’m daft, and this is how I do it! Have Pride!
Remember technology is supposed to work for you!
End of Document – By Jason P Sage
These are just notes I had written down before writing this document
00000000
binary to decimal conversion cheat sheet
128 64 32 16 8 4 2 1
--------------------------
1 1 1 1 1 1 1 1
0 1 2 3 4 5 6 --- 255
ASCII
64dec = A
1 mybyte = "A" = 64
2 mybyteb = "B"
true = (mybyteb > mybyte)
above just a algebraic truism
Because ASCII code for "A" is less than "B" because ASCII 64=A and 65=B and 64 is less than 65
Computer Science 101


