Question:
What is binary?
Answer:
EVERYTHING on your computer is represented as a 1 or 0! That is binary. Humans, with our ten fingers, are accustomed to decimal: 1 - 10. A
human example of binary would be the simple on/off light switch. The light is either on or off, period. Not both, not neither. Not on part
way, or off just a little bit, but strictly on or off.
Each 1 or 0 on your computer is called a
bit: binary digit.
Bits are organized into groups of eight to form what are called bytes: binary term.
One byte provides 256 possible combinations of 1s and 0s. Two bytes provide over 65,000 possible combinations. A mere 4 bytes provide over 4 billion possible combinations of 1s and 0s!
Bytes are stored in either of two types of memory:
storage, or volatile.
Storage persists after the computer is turned off, while volatile memory is erased.
Question:
How are those bytes physically stored on the computer?
Answer:
Two storage devices are hard drives and disks.
Hard drives manipulate north/south directions of tiny magnets and can store over 200GB (gigabytes) of data.
That is over 200 billion bytes!
CDs, DVDs, and Blu-ray disks have tiny dimples that reflect
(or not) laser light to store up to 27GB.
Volatile memory, or RAM
(Random Access Memory) silicon chips,
contain microscopic transistors, each holding a high or low voltage to read and write 2GB of memory or more.
Another type of storage is a USB
(Universal Serial Bus) flash drive,
which also stores bytes on silicon chips, but unlike RAM, flash memory retains
its data independent of the computer.
Question:
What is the process to read and write those bytes?
Answer:
The CPU (Central Processing Unit), such as an Intel Pentium microprocessor,
does the heavy lifting of setting and retrieving those 2 billion or so RAM high/low voltages. The OS (Operation System), such as Microsoft Windows,
provides the CPU with instructions and makes sense of the results. Today’s CPUs can process instructions at several hundred billion cycles per second,
with their clock speed measured in GHz (gigahertz). Computer design and hardware such as motherboards and bus cables further enhance the
speed of delivering and interpreting those bytes.
Computer programs, or software, come in 2 flavors:
the OS or system software, which controls the hardware, and application software or API (Application Program Interface), which works with the OS to provide the user interface, so you can send
an email, or chart company sales figures.
APIs communicate with the OS, which in turn communicates with the hardware such as monitors, hard drives, and
printers. An API requests, and is allocated a block of RAM from the OS at a virtual memory address to arrange those 1s and 0s in a way the OS understands, so it can tell the
hardware to display text on the monitor, print a picture, and so forth.
Question:
How are computer programs built?
Answer:
Computer programs are sets of instructions written in human language text called source code, and must then be converted into binary for the OS
to understand. Programmers can use text editors, from simple Notepad, to a complex IDE (Integrated Development Environment) such as Visual Studio,
to write source code. Some programming languages, such as C# and Java, compile the source code, i.e. convert into binary, before the program is run.
Other scripting languages, such as PHP and JavaScript, use an interpreter to convert source code into binary at the time the program is run. Intuitively, you
might correctly recognize that compiled programs run faster, as the conversion to binary has already been completed. For small programs with today’s
computer speeds, while the computer may notice a difference, it will be hardly noticeable to humans.
Question:
What are some of the challenges in writing a computer program?
Answer:
Writing text-based source code that can be converted into binary is accomplished by following rules of syntax and spelling. Just as proper grammar and
spelling help humans understand each other, syntax helps the OS understand an API. Compiled languages such as C# and Java will not
convert into binary if the syntax is not correct, preventing the program from being created in the first place. Interpreted languages such as PHP
and JavaScript may run on the computer, but with errors. These are called compile or syntax errors, and are the easiest to correct. In human
terms, they would be like misspelling or mispronouncing a word, so that no one else could understand it.
If the API does convert into binary and the OS understands the instructions, the instructions still might be incorrect – these are called logic
errors. For example: adding 2 plus 2 and getting 5. These errors are harder to find and correct, and might not always surface to be noticed, as
3 plus 3 may correctly return 6, but no one tested adding 2 plus 2.
Finally, an API might get past syntax and logic errors, only to have a disconnect between the OS and hardware called runtime errors, perhaps causing a computer crash.
These can be the hardest errors to find and correct. For example, an API may be writing to one block of RAM, while the OS is reading a different
block.
Question:
How do programmers find and correct errors?
Answer:
Tools to find and correct these errors are called debuggers.
Programmers can watch their source code in real time as the API executes,
inspecting data and behavior to see if the results are what they expect. Debuggers help programmers pinpoint the exact line of code where the
program fails. A common bane among programmers is that the computer does exactly what it is told, not necessarily what the programmer wants.
Question:
What are some differences between good and bad programs?
Answer:
Besides getting an API to run correctly, the goal among programmers is to achieve that end by using the least amount of memory and requiring the
fewest number of CPU instructions. The term for that is "elegant" code. However, programmers must strike a balance between the most efficient
code, and code that is easy to maintain, understand, and modify. Consider the following code, for example:
dsp(p+t);
That doesn’t exactly lend
itself to understanding what the computer is doing, but it runs efficiently. Compare:
total = price + tax;
Display(total);
Maybe not as
efficient as the first example, but certainly easier to understand, and make a change later on if needed – if taxes increase, for instance.
Programmers aim for a middle-ground between the 2, where the code is both efficient and readable by humans.
On a historical note without going into great detail: in the early days of computer programming,
you know, when dinosaurs still roamed the earth, source code was not human language text.
Programs were written in "machine language".
Before that, there were punch cards... Also, computers were not as fast as they are today.
Therefore, performance of a poorly written program was clearly evident, making the goal of elegant code extremely important. Even today, a program that efficiently searches
an Internet inventory database of thousands of items, and a program that is inefficient, could make the difference between a sale and no sale.
Summary
In summary, computers know only 2 states called bits that humans represent as 1s and 0s. But computers know tens-of-billions of those bits,
arranged in groups of 8 called bytes, and that is enough to enable a computer to play video and sound, calculate Fibonacci numbers,
and download web pages. Ultimately: it is the programmer who makes all of that happen – directing the OS to deliver proper instructions
to the CPU, monitor, printer, and other hardware.
Webopedia Computer Search Terms:
address
API
application
binary
bit
bus
byte
chip
clock speed
compile
computer
CPU
data
database
debugger
disk
flash drive
flash memory
GB
GHz
hard drive
hardware
IDE
instruction
Internet
interpreter
machine language
memory
microprocessor
monitor
motherboard
OS
printer
program
RAM
real time
silicon
software
source code
storage
syntax
system software
transistor
USB
virtual
volatile