No, you don't need to know what binary is, or how it works. Nor do you need to understand how everything down to the bare metal, works. However, knowing that sort of thing can be helpful in some unforseen circumstances, and the more you know, the more options you have. So, let's move to the netherworld of computers, right up next to the cpu. We'll look at how computers speak in different bases, and then look at the day of a computer from power up to shut down.
Computers don't understand numbers, at least the way we do. Computers well understand the concept of 10 (as far as machines can understand) but to a computer, 10 is 2. Really. We think of numbers in sets of ten; we have ten fingers, and ten toes. And the number 10 is the first number to have two digits, and 100 is 10x10. Each new 'place' to the right holds values greater than the place to the left by a factor of 10. This sort of a system is called a decimal system, after some greek or latin prefix that denoted dec- as meaning ten.
However, computers, at the lowest level, have switches that can only be on and off. If a switch is turned off, it's represented by the numeral 0, and if it's on, by the numeral 1. With only one switch, you can only represent two numbers: 0 and 1. If you want to represent larger numbers, you need more switches. Let's say you have three switches now, and each on switch is counted as one. So, if you switched each one on, you have a representation of three.
What if I told you that three switches could represent numbers up to 7? Now, looking back at the decimal system, where each added space should be larger than the previously largest place by 10, we can adapt the same system to switches: since we have only 2 numerals (versus 10 in the decimal system), let's try increasing each place by a factor of two. Thus, the left place will be 1, the middle is 2, and the right switch is 4. Let's look at making all the numbers, 0-7, with our three switches:
This system is called binary, or base 22, and just like the decimal system, it can be extended to infinity. Binary is the least likely sort of number to show up in your programs, though. There are two other bases that show up far more often, base 16 (hexidecimal) and base 8.
How is the computer supposed to know how long a number is? In computer speak, a single switch is a bit, on or off. If you put 8 bits together, you get a byte3, which holds a maximum value of 255. Obviously, computers can handle numbers larger than that, but if you just starting adding bits to the end of a byte to make it hold a number larger than 255, then the computer won't know where one number ends and the next one begins. You instead add a byte to the end, which is known as a word, which can hold a maximum value of 65535. Then how are you supposed to know if a number takes up a byte or a word, or something larger? The answer lies in C++'s type system: each int takes up a word (on most 32-bit x86 systems) and a long int takes up two words, or a dword4. The machine code, using that information, 'knows' the number of bytes to use for a certain number.
So you've been around your local technology stores, and you might have noticed that some computers are marked 32-bit or 64-bit. The bit-ness of a computer depends on the number of bits that a cpu can handle at one time. That means that 64-bit computers can handle a larger number everytime it does a computation, which is good news for computation intensive media editing. The more bits, the better!
So how do you mark numbers as negative or positive? When you write binary numbers, you can just prefix a - to the beginning, like you've been doing with decimal numbers all your life. But with computers, there's no little - switch. Or is there? So computer people long ago decided that because there was no magical - bit, we would have to set aside a bit to signify the sign of the number. So, if leading bit on a number is 0, then it's positive: otherwise, it's negative.
If you've been wondering how the computer knows which order the binary number goes in, then you're not alone. Enough people in the past have championed forward order and backward order that programmers have term for such people: little-endians(small to large) and big-endians(large to small), which are names taken from swift's novel, Gulliver's Travels, because the byte order is ultimately pointless, especially today. When computers were 30 hz beasts that took up a room, you could do some optimizations, depending on which order you used, that could actually affect the run time of a program. Today, all you need to know is the way a certain file is ordered: big-endian or little-endian? when you write programs to use that file format.
Base 16 is somewhat like decimal, except that including the numerals 0-9, you can use the 'letters' A upto F. Except they're not letters anymore, just more numerals. So the numbers up to 9 are represented the same, but 10 in decimal is A. Here's a some decimal numbers converted to hexidecimal:
Why would any punish themselves with this? Well, this is the way that the computer maps out it's internal memory. The number of bytes avaliable to the computer comes out to a round hexidecimal value, so if you ever deal with pointers and memory addresses, and you inadvertently print out a pointer, it'll come out as a hexidecimal address. Also, it's used for passing flags to functions: instead of comparing multiple numbers or booleans, all you need is a one number that gives meaning to each place in the binary equivalent, and efficient bit pushing functions can figure out which place is switched on and off. For instance:
p>binary 00011001; 0 off, 1 on, option 1 is on 2, 3 is of 4, 5 is on 6 - 8 is off
Since binary isn't especially compact, though, hexidecimal is an acceptable substitute.
Even though I don't see it around often, base 8 can be useful:
And so on. If you want to play with your bases, here's a little base convertor:
Number: | |
From base: | |
To base: |
So knowing how binary works is nice and all, but let's get down to how the computer is born and dies: okay, maybe wakes up and goes to sleep is a more apt metaphor, but still: let's get started!
You push the power button, and your computer turns on. First, the power supply, which converts power fed in through the outlet to suitable use for the computer, is kicked on so other things can start to function. Then, the motherboard recieves power and starts the BIOS, or basic input-output system, and loads at least one driver, a basic video driver. At this time, you usually see a splash screen5 with your computer vendor's logo flash by with instructions, perhaps in the corner, that pressing some key will start you in safe mode and some other key will get you the BIOS menu. I recommend that you take a walk through your particular BIOS, if for nothing other than knowing where to go if you have a serious error.
Usually, getting to the bios requires hittng either Delete or an F(x) (where x is a number) key; on Dells, it's F2. The BIOS can load quickly, so it's important that if you want to get into the BIOS to act quickly also!
Essentially, two things happen when the BIOS loads: it checks out the system, making sure nothing is terribly wrong, and then finds your hard drive and boots Windows. However, if you told your bios to boot from something else, like a cd or floppy, then it would check there first. That's how you can install Windows on an empty box. Once it finds the appropriate medium (be it cd, floppy, or hard drive) BIOS then checks the MBR, and loads the boot loader.
Usually, the MBR is the first sector, or ring, of the hard drive (circular hard drives, yes? just in case you forgot) which holds the boot loader. The boot loader takes over from the BIOS, and sets out to load the actual operating system. Most Windows operating systems, when they're installed, automatically hog the MBR with their own boot loader, which isn't a bad thing: it ensures the computer gets booted when it's turned on. Its run as a blank screen, so you don't know it's there. Real power users, though, sometimes double or triple boot (or however many times boot), which is putting 2 (or however many) operating systems on the same computer and having a boot loader that gives you the choice of which one to boot. As I said, it's real power user stuff, and you probably won't need it.
Okay, you're insane. You're using windows, and you want to double boot. If you use linux, you already have a configurable boot loader. If you want to run two different copies of Windows (testing software, perhaps), though, I recommend that you first take a look at Microsoft's solutions; Professional versions look like they have boot loader configuration files somewhere, and configuration tools to edit them. Looking it up on the Microsoft website is probably the best way to go. If you're looking for something more grungy and have two blank cds laying around, you might try editing your partitions with a gparted live cd, and then installing lilo or grub with the live cd. I haven't every tried this, and I don't intend to, so you can tell me how it goes. : )
After the boot loader starts loading the OS, well, the OS takes over and you get the traditional Windows logo and fake status bar that doesn't tell you anything until your login screen appears. And after that, I'm sure you know what happens.
So you're tired, it's been a wild day of online gaming and hacking out code, and you want your computer to sleep so it can be rested for the next day. So, you go to Start>Turn Off Computer>Shutdown, and your computer sends a kill, or shutdown, message, to all of the non-essential processes on the system. If you've ever had a non-responsive program, and tried shutting down, you might have been able to stop the shutdown by selecting 'cancel' when Windows asks you if it should kill this process or another.
Sometimes, the weirdest programs are unresponsive. If there's something that you have never seen before, and it refuses to shutdown, first, wait for Windows to decide that it's not going to respond, and then agree to kill it. Any other time, it's a bad idea to kill random programs, but it's shutting down: the worst that can happen is a complete freeze, in which you'll have to do a hard shutdown, which is essentially the same thing you were trying to do. If the same thing messes up everytime you shutdown, you might have a problem: check out the process that won't die the next time you're on the web.
After all the applications have died, then Windows goes into the blue screen 'Windows is shutting down' mode. At this time, Windows updates itself and ensures all the changes you made to it get written somewhere, so the changes can be persistent, or there the next time you boot up. Finally, Windows hands off control to the BIOS with instructions to shut down, and terminates itself. The process after that is usually quick: the BIOS dumps memory out, saves any configuration changes, and then shuts off power to the power supply, which stops anything else not already stopped. And the computer is still.
If you hold your button for more than 5 seconds, your computer will usually instantaneously shutdown. Usually, you'll also lose all of your unsaved information. It's quite helpful for getting out of frozen computers. The only way I can think if something shutting down so fast is by shutting down the power supply. In this case, however, you might want to wait a few seconds before turning the computer back on, because memory can persist for a few seconds before it resets. If memory from a previous hard shutdown is still around, it can screw with things.
Depressing, eh? Now that the computer is dead, let's wear some black, and go looking for boxes!