|
CogSci 3 |
Introduction to Computing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Binary Numbers(Uses JavaScript and requires Netscape 3.0 or Internet Explorer 4.0 or higher)Number SystemsTo get the total value of a number, say: 1,234, you take each digit and multiply it by the appropriate power of 10. Then add the all products up to get the final value. This procedure may be so ingrained, that it seems silly to even talk about. Maybe the following table will help illustrate the details.
Okay, so what? Well, there are number systems based on values other than 10! Binary NumbersWe don't usually worry about binary, because when the computer prints out a number for us, it has been translated into decimal. Similarly, when we input a decimal number into the computer (say, into a spreadsheet), it is translated into binary. The table below shows some binary numbers and their decimal equivalents. As you can see, binary numbers can be very long (many digits) and cumbersome to read and write. For instance, 10000001 is the same as 129 in decimal! However, when programming a computer, it is sometimes convenient to work directly with binary and to specify the value that each bit in a binary number will have. Enter hexadecimal. HexadecimalHere is our example of 1,234 again, only as a hexadecimal number. In hex, its just 1,234. But the table translates each digit into a decimal equivalent.
Since each hexadecimal digit represents (exactly) 4 binary digits (or bits), the numbers are much shorter than the binary equivalent. Eight bits make up a byte--2 hexadecimal digits. Each hex digit in a byte is also called a nybble. Each byte (2 hex digits) is a hexadecimal number between 0 and FF (which is 255 decimal). A Byte is a Byte
It's a tad more complicated than that. In most modern computers, like PCs and Macintoshes, the exact interpretation of the value in a particular byte in the RAM is up to the software program that is looking at it. Say a particular byte contains the binary number 1000001, which is 41 in hexadecimal, or 65 in decimal. That bit pattern can also represent the ASCII (American Standard Code for Information Interchange) code for the letter "A"; i.e., the printable letter capital "A". (The code sent to a printer to cause the letter "A" to appear on the page.) That byte might also be part of a computer instruction, (also called machine language) like Add, or Compare. Or that byte might be part of a longer sequence of bytes that comprise a 16 bit, 32 bit, or 64 bit number! Perhaps that byte is part of the RGB (Red Green Blue) color specification of a Web page background color or font color. Or part of a black and white image in which each single bit specifies if a pixel (picture element) is black or white. The interpretation of that byte is determined by the software programmer who wrote the software which is looking at it. Let's Get NegativeIn our human decimal system, we just prefix a negative number with a minus sign ('-'). But computers only have bits to represent things. It is possible to designate a sign bit to say whether the value was positive or negative. This turns out to be wasteful in terms of storage, that sign bit can't also be used as a numeric value. Instead, most (not all!) modern computers two's compliment notation for negative numbers. In two's compliment, the highest order (most significant-- leftmost) bit determines whether the value is positive or negative. If the bit is "on", a 1, then the number is negative. Otherwise, it is positive. So our lowly byte, which we had been viewing as unsigned (positively only) had values been 0 and 255 (decimal). As a signed value, it can have values between -128 and 127. Which interpretation, signed or unsigned, of the bit pattern is up to the software looking at it. The Binary WorkbenchThe Format pop up menu lets you choose your interpretation of the 16 bits: unsigned decimal, signed decimal, ASCII, etc. When you select a new output format, the output will be adjusted accordingly. Some things to try:
* Until recently, ASCII was a 7 bit code, values between 0 and 127. When building the ASCII output formatter, I couldn't decide whether to just interpret the low order 7 bits or show the new values above 128 too. I decided to try the latter. I include quotes ('"') around the ASCII codes to remind you that they are a character string. So, "CA" are the printable characters C and A, which are different than the hexadecimal value CA. The quotes also let the space character "show up". Finally, control characters which have values between 0 and 31 typically do not have a printable form. I translate those as a carat ('^') followed by the letter you would type with the control key to input that value. E.g., hexadecimal 01 will show up as "^A".
Terms to Know
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||