r/computerscience • u/H2L1_Yogi • Feb 14 '21
How Computers Work: The Basics
Novice networking student here and I'm very interested in getting a better understanding of how computers work. The "smallest" part of the computer that I've learned about so far is binary. The thing is that I don't know where binary comes from. I've asked around and gotten the answer that it comes from electricity that is either above or below a certain voltage threshold.
So from the wall outlet electricity is fed to the power unit of my tower. From there the motherboard is powered, but how is the binary (which is digital) created? I'm looking for a simple explanation if at all possible. I'm not super technical and I'm honestly not wanting that kind of explanation, but if that's what you can offer, please send it my way.
14
Feb 14 '21 edited Feb 14 '21
There is a very good textbook I used for my computer architecture course, is called:
Computer Organization and Design By David Patterson and John Hennessy
The current editions tend to be quite expensive, but one that one or two editions from current should be just as good for learning the basics.
The very first thing you need to understand, is called the Von Neumann architecture. It doesnt matter if you're talking about a PC, a Mac, laptop, desktop, phone, tablet, etc. These all essentially work on the same constructs. There is a main data bus (think of that like a multi lane freeway), and there are on ramps and off ramps that connect your peripheral I/O devices, primary storage (RAM), secondary storage (hard drive/ssd/etv), and a processor. There are actually two busses, a high speed and a low speed bus, but that's sort of irrelevant.
Since you know some basics of binary, I can give you the most ELI5 explanation. Data is represented in binary, but so are the instructions that are passed to a CPU. These binary values are just high and low voltages stored in capacitors and passed through the hardware using logic gates that open and close pathways for the electrical currents to flow between the memory, harddisk, and CPU.
Instructions are just strings of binary values. they usually contain the operation code (telling the CPU what to do), and some address (location in memory), a list of registers, or some data itself (aka literal or immediate).
It may say, take the value stored in register X, add it to the value stored in register Y, and put the result in register Z. It may also say, go get some number of bytes beginning at memory location X, and put that data in register Y. It could also say, here is a specific value, put it in register or memory location X. Another kind of instruction may simply say, here is the memory location that contains the next instruction to execute.
There are logic circuits that interpret the bits and those bits controll the digital logic that tells the CPU what to do.
3
u/Poddster Feb 14 '21
This is an excellent book, but I wouldn't recommend it to someone who doesn't even know what binary is.
1
Feb 14 '21
It sounds to me as if the op knows what binary is, though he might need an intro to digital logic to fully benefit from this book.
0
u/Poddster Feb 14 '21
The "smallest" part of the computer that I've learned about so far is binary. The thing is that I don't know where binary comes from.
That doesn't sound like they know what binary is, to me! :)
1
u/magical_h4x Feb 14 '21
I'd also like to endorse this recommendation. I think it's likely that after learning a bit about the subject, OP will be interested in the details this book talks about
13
u/berrmal64 Feb 14 '21
Code: The Hidden Language of Computer Hardware and Software is a book by Charles Petzold, it's really easy to understand, and maybe perfect for you, as it starts with simple light switches, and works up to describing the core of a cpu without ever getting too very technical.
3
6
5
u/desutiem Feb 14 '21
So at that level its about electronics. So if you look up the vacuum tube then the Transistor which are both physical material objects that can take an input signal and then send out a signal or not depending on the input. This is a rudimentary explanation but that gives you your binary. Electrical current present - 1, not present 0. In practice its more about voltages above and under a certain level etc, but you get the idea.
From there you ‘chain’ them together to create something called logic gates and this is where you can start creating something that can perform logical operations or mathematical operations.
You’ll have to do further research to understand the details and a simple understanding of electronics helps but this might satisfy you enough!
Also as people as saying, the recommendation of Code by Charlez Peltzoid is a great one.
7
u/Revolutionalredstone Feb 14 '21
Basically a computer is a calculator and a scratch pad, you give the computer a bunch of instructions in the form of 'take this value and add it to that value and store that here, then check if this value is above 5 and if it is then go do this list of things' once millions of these instructions are being done per second you can have the computer be able to do pretty much any kind of information manipulation task.
3
Feb 14 '21
There’s a good textbook called Introduction to Computing Systems by Yale N. Patt and Sanjay J. Patel that answers all those questions and more
3
3
4
u/melanieshelton914 Feb 14 '21
But How Do It Know? Is a really good book that explains how computers work in a very simple way. There’s also a short YouTube video that sums up the concepts in the book.
But How Do It Know? - The Basic Principles of Computers for Everyone https://www.amazon.com/dp/0615303765/ref=cm_sw_r_cp_api_glt_fabc_WM1AQKMRCGNFPYW5T2F5
2
2
u/Poddster Feb 14 '21
I completely disagree and think that this book is terrible compared to the alternatives, e.g. Code by Petzold. It's far too wordy, and yet doesn't out those words to good use in explaining the concepts well.
4
u/Poddster Feb 14 '21 edited Feb 14 '21
I highly recommend the book Code by Charles Petzold. It's singed at the general reader who knows nothing about computers, but did successfully walk you through the concepts from electricity in your wall to a CPU doing stuff.
Alternatively, watch some videos:
https://www.youtube.com/watch?v=J3ekb5JnX8Y&list=PLfYdTiQCV_p6lhKbGcjVIy0KIHxXq3HDy&index=37
https://youtube.com/playlist?list=PLFt_AvWsXl0dPhqVsKt1Ni_46ARyiCGSq
https://youtube.com/playlist?list=PL8dPuuaLjXtNlUrzyH5r6jN9ulIgZBpdo (start at video 3)
Good luck.
2
u/MirrorLake Feb 14 '21 edited Feb 14 '21
Each PC component (CPU, RAM, HDD/SSD) has their own technique of representing 1s and 0s at the hardware level. You may want to narrow your focus and read about each one separately.
If CPUs are your focus, I would recommend starting by reading about a much older CPU like the Intel 4004 because it's a simpler design and the schematics are of course much easier to read than a modern CPU. CPU circuitry ultimately uses logic gates to create binary adders and multipliers as well as other circuits to perform basic mathematical operations. The flow of electricity in a wire is a 1, and no electricity is treated as a 0.
Going down to the simplest level, a tutorial like this one might be a starting point when trying to build up and understand logic gates -> adders and multiplexers -> rudimentary CPU schematics.
2
u/OphioukhosUnbound Feb 14 '21
A book you might like: Secret Life of Programs
Gives a lot of overview of how computers work from the ground up. From hardware to software. With a lot of history on how things started and developed. Written at a very accessible level.
It’s a hard subject to cover but having read it one gets a good broad picture of how things developed and work at various scales with enough detail to outside specific questions more easily.
I don’t know what other titles attempt something similar, but reading this book or one like it is very valuable if one wants context for practical programming, imo.
2
u/SecludedSandwich Feb 14 '21
I studied Computer Science, and the best and most compact explanation I ever found is this excellent series from Crash Course. Helped me understand the big picture of what I was learning in class a lot better.
3
u/w3woody Feb 14 '21
Okay, let me take a stab at this. I started putting together a series of videos on YouTube, but life caught up to me and I was unable to get to counters and decoders and stuff. (I have the transistor circuits designed; I just never got around to making them and putting them together.)
but how is the binary (which is digital) created?
So all this starts with a transistor.
A transistor is basically a thing which amplifies the voltage signal applied to one part of it. So, if you input (say) a signal which changes the voltage by 0.5 volts, the output may swing by (say) 3 volts.
That's useful if you want to (for example) build a sound amplifier, because you can increase the intensity of the input voltage (like, say, from a signal from a radio circuit) enough so as to power something else (like, say, the speakers of your car radio).
Of course that amplification can't go on forever. If the maximum voltage in your system is (say) 5 volts, then if you apply a little voltage to the input of the transistor, the output swings the full five volts.
In this mode the transistor acts like a switch.
Technical detail that's important here: some transistors, when turned on, drive the voltage off--not on. That's why I talk about the "swing" of the voltage above.
Now if we by convention call (say) "on" 1 and "off" 0, we now have binary. "Binary" is basically counting by base 2--but our "digits" are actually the voltages on a wire or across a transistor. It's 1 if the transistor is on, 0 if the transistor is off.
Knowing this, we can do clever things with these transistors. A transistor which turns off when voltage is applied to its gate is a "NOT" gate: 0 goes to 1 and 1 goes to 0.
You can also put two transistors like this together to create a "NAND" gate and a "NOR" gate--a gate which turns off only if both inputs are on, and a gate which turns off if either gate is turned on. Add with a NOT gate and your three transistors gets you 'AND' and 'OR': gates that turn on if both inputs are 1 or if either input is 1.
Another gate you can build using these NAND and NOR gates is a bistable gate, or rather, a 'flip flop.' A 'flip flop' is a series of transistors that can "remember" (that is, if you apply voltage to one of two inputs, one of the two outputs switch on and the other switches off--and remain that way even after you take the voltage away).
Bistable gates are interesting because from them you can build primitive memory: things that remain on or off even after the input is taken away.
And you can also build counters: things that keep track of the current count and increment each time a pulse is added.
If you're especially clever you can even design circuits that can count up, count down, and store an input number (in binary).
These circuits are so useful that we manufacture chips which just contain these circuits. For example, this is the 74F269 chip, an 8-bit counter which can store an 8-bit number (applied as 8 input pins that are either on or off; 1 or 0), and both count up and count down. There are literally thousands of different discrete logic chips like this, from simple NAND gates to very complex circuits.
Now a computer--well, it's a whole bunch of this shit tied together. Take a bunch of bistable circuits and tie them together, and you have registers. You can use counters that are designed to latch and count up and down as special registers like the "Program Counter", which stores the address of the next "instruction" you're planning to execute.
You have an arithmetic logic unit which is basically a vast array of transistors which know how to do things like "add" and "subtract" using a lot of and/or/not circuits.
"Instructions" themselves are basically bit patterns in memory which are 'decoded'--translated through a vast array of and/or/nand/nor/not gates--into signals on wires that signal to a register (for example) "store the value on the wires".
So, for example, if you're adding two numbers together from memory, your instructions to do this may translate to:
Pull the wire to tell the external memory to present the value of that memory on a bunch of other wires we call a "bus"
At the same time, pull another wire that tells register 'a' to store the value.
Next, Pull the wire to tell the ALU to turn on the circuit which "adds" the input from register a and what's on the bus
At the same time, pull the wire which tells register 'b' to present its's value on the internal bus.
Finally, pull the wire that tells register 'a' to store the value that's presented as the answer from the ALU.
It gets very complicated and involves thousands upon thousands (or, in the case of modern CPUs, millions and millions) of transistors carefully arranged in these complex logic circuits.
But it all really starts with the transistor, acting as a switch.
2
u/bassanaut Feb 14 '21
I think the first thing to understand is what transistors are, and what boolean logic is. Transistors are how we figured out to create a 'switch' much like a light switch, it has an off state or an on state, which we in turn represent with a 1 or 0, except that is doesn't require any moving parts. Using boolean logic we can now use a series of 1's and 0's to create 'logic circuits', like if, or, and. Im not a comp sci student just an idiot ironworker so please correct me if I'm wrong anyone!
1
u/vijay266-cbr Jul 04 '25
What are the rules and regulations in India ,to open a computer institute ?
1
1
1
u/jpayne36 Feb 14 '21
Nobody’s answering op’s question lol, he didn’t ask what the 1s and 0s mean, he asked where they’re actually created.
1
u/Poddster Feb 14 '21
Nobody's answered the question because it's unanswerable. Binary isn't a substance. 1s and 0s are not "created", they're simply concepts
1
u/Ascomae Feb 14 '21
Ok, don't hate me for this.
That german video explains a computer to children. I don't know, if I has enough sub titles.
I think it's really deep
0
u/mattcj7 Feb 14 '21
What’s more interesting is players making simple computers in Minecraft using the switches. Very impressive
2
0
u/berrmal64 Feb 14 '21
They've been doing that in Dwarf Fortress with captive animals and non-newtonian fluids for many years.
84
u/[deleted] Feb 14 '21 edited Feb 14 '21
the binary is just a numerical representation of a physical reality. the ones and zero's are ons and offs of switches or more technically they are the high and low voltages that turn on and off transistors.
there are some key electrical components that make up the computer. there are probably more than I list here too.
multiplexers -
demultiplexers -
memory -
clocks -
buses
and custom circuits for dedicated functions like doing math with a binary number system or outputting to a screen or speaker ect.
multiplexers take a series of inputs (ons and offs) (typically in parallel I think) and produce a single output on or off
de-multiplexers take a single input on or off and output a series of outputs (in parallel again usually I think)
memory are special circuits that use their own output as part of their input (via a feedback mechinism) that lets them store signals to be used later. importantly the ability to store a specific signal can be turned on or off.
a buss is just a line in common to different parts of the computer
and a clock is a circuit that oscillates it's output.
one important use of a multiplexer is that it lets you send signals down a bus that only one unit will respond too. a example of this is computer memory. the address of a memory unit is a series of bits say (1001 0100) for example and that data to be stored is sent with it to the memory unit. say the value (0000 0101) then inside the memory unit their is a multiplexer that turns on a specific memory "cell" when it receives the address (1001 0100) it then checks if it needs to reed or write (in this example it's write) and it stores the value of the data (0000 0101) to be used later.
a de-multiplexer is used when several pieces of machinery need to coordinate you can have a multiplexer check for a pattern or "instruction" and then send out a series of signals turning on different parts of the machine. this might be a bad example but maybe a "load" instruction would have a multiplexer turn on the "load" de-multiplexer which would turn send a signal as address to the memory unit from a specific memory "cell" it then would send another signal to another memory cell in say the ALU or somewhere else to listen to the signal from the memory unit.
all of this so far has been abstracted away from time. in reality each one our operations will take some amount of time how long exactly depends on the operation involved. the clock is a oscillating circuit that everything else in the computer (basically I think) listens too so that operations can be synced up and work at the same time. asynchronous circuit design is a thing but I'm not aware of any mainstream uses of it could just be ignorant however.
buses are just wires connecting other wires together all at once so every unit can "hear" the others when they "communicate"
so that's how the hardware works used to make one but how does a actual computer put it all together? there are different architectures but basically a computer has two main components and very often some very common and important peripherals. the two main components are the memory unit and the processing unit. the memory unit is conceptually really simple its just a lot of memory cells that can read our write data depending on a address signal interpreted by a multiplexer and a read or write command which can just be a on or off signal. the processing unit is either a command matrix (basically de-multiplexers hooked up to multiplexers) or has a tiny memory unit of it's own that has a stored program that just executes some specific commands in a fixed pattern.
I could be wrong but it's my understanding is that the basic program structure is load a specific register X with the value in memory of the register PC (program counter which usually starts at 0) read the instruction of the instruction section of the contents of register X apply the instruction check if a new value needs to be executed (because the instruction might have put a new value in X) add 1 to the value in PC and repeat.
so now if that works you have a machine that will read through memory sequentially unless it's given a jump instruction and will send out a series of commands or do nothing based on what's in that memory. at it's most basic that's all a computer is. you could make it "compute" functions by storing tables of values in memory (similar to the CADET system) but that would be inefficient so typically there is at the very least a component that does the math on a binary number system for you called the ALU. (arithmetic and logic unit.)
as for other hardware add-ons like screens mice keyboards and speakers its my understanding that the implementation will vary but that either there will be dedicated hardware support for it or the computer will "pretend" that hardware for such is just computer memory and rely on a software interface to send "magic values" to make the things work.
so that's my summery in both too little and too much detail
https://www.allaboutcircuits.com/textbook/ for basic electronics info
more details on a certain kind of computer