Book - Code: The Hidden Language of Computer Hardware and Software - Notes
Chapter 1 - Best Friends
- The code is the system to transform information among humans and computers.
- The language we talk is a form of a code only intelligent people that have the fundamentals understand.
- The language we write is another form of code (printed media). If you know how to map letters to words you can easily communicate with other humans.
- For people not able to talk there is a sign language which is another form of a code.
- So code is not only for computers to understand we also use it for other purposes.
For two people living across the street (two friends) communication is a problem when their parents do not allow them to be awake really late so they need to come up with a system to communicate. Consider their window look to each other. How they are going to communicate. Here are the options:
- wave each other with hand gestures (hard to do and understand & no use without light)
- use a flashlight to draw letters with light (not so precise hard to understand which letter & even words)
- use a flashlight with some order to map each letter to blinks (too long time consuming, Z 26 times)
- So this seems like a problem but someone already found a solution with Morse code. Each state can be represented with on/off actions on the flashlight.
- Dash is a long press on the flashlight and dot is a single action of making flashlight on and off instantly.
- By using this technique and each party knowing these codes (memorizing) easily communicate with each other. It even includes numbers and punctuations.
- They can even use Morse for verbal communication let dot be dih and dash be dah and you can easily communicate with each other. What matters is two different things whether it is a letter, gesture or something else and you can do most of the things.
Chapter 2 - Codes and Combinations
One interesting aspect of Morse code is that representation of letters distributed by how many dash and dots they represent. Some have single dash/dot other have 2 dash/dot and so on. If we look at how many things they can represent for
- 1 dot/dash = 2 letter representation
- 2 dot/dash = 4 letter representation
- 3 dot/dash = 8 letter representation
- 4 dot/dash = 16 letter representation
- That is total of 30 letters which is enough to represent all letter of the alphabet.
- We can add one dot/dash to make the set bigger for numbers.
- 5 dot/dash = 32 representation
- Now you can represent 10 numbers and 16 punctuation but if you want to also show all punctuations you need to add one more.
- 6 dot/dash = 64 representation more than enough to cover rest of punctuations.
- From this aspect, it seems like as we add a new element set of combination doubled. In each set, we literally add dash and dot to every combination so as a result, we double the set size in each time.
- Simple formula #number of representation = 2 ^ number of dot/dash
- Similar situation with the coin you only have binary outcome either it is head or tails.
Chapter 3 - Braille Codes
- The biggest invention was not the morse code but was something called Braille.
- It was invented by a person which accidentally got blind.
- What Braille system does is you have two columns of 3 dots. Each dot can be in either raised or flat state. If it is raised it means it is on otherwise it is off.
- With this system, we can represent the 26 letters of the alphabet easily.
- All we have to do is raise some dots for some letter and we are done. But of course, we need more as we use much more than 26 letters when we are writing (especially numbers, punctuations and capital etc)
- With 6 options we can generate 64 combinations. 2^6 = 64
- 26 for letters, 10 for numbers, the rest for punctuations and some shift codes to mention that incoming Braille is a letter or vice versa. (like a switch to on and off the interpretation) Also, we have capital indicators that mean incoming thing should interpret as capital.
- To understand upcoming number we have switch codes when they used on it is own it states that incoming codes are for the number.
- In total with 64 representation we can create a new language (or code).
Chapter 4 - Anatomy Of Flashlight
- Now, the flashlight is a nice way to go deeper. The flashlight is composed of one battery, one switch and one lightbulb that lets you switch with on and off states.
- But how does it really work? How light lit anyway?
- We know that all matters composed of atoms. Atom is a combination of neutrons, electrons, and positrons. Neutrons and positrons stay at the nucleus and do stand still but electrons just revolve around the nucleus.
- The id of an atom is based on how many positrons it has like lithium has 3 so its atomic number is 3.
- Atoms like oxygen and hydrogen form what is called molecules. And molecules with other molecules form compounds.
- When the bulb lit it is because of the movement of the electrons nothing else. Batteries have chemical reactions inside them and this produces electrons to move from one side of the battery to another side of the battery. (anode, cathode)
- But still, we need some kind of conductor to move these electrons which is the wire. Wire basically take an electron from the battery, move to another atom and this goes on until plus side of the battery and produce a current which lit bulb.
- Voltage means potential, not an easy explanation. If it is a brick sitting in the floor it has a potential of 0 when you move to your hand it has now potential because you can drop it from there.
- current means throughput of the electrons passing through at one time. (water analogy amount of water passing through)
- resistance means how likely this matter allow passing of electrons. (water analogy how wide the pipe is)
E = I * R
With just battery and wire without anything else, it will be a really small amount of resistance and it will start to heat up and burn eventually. Because battery has so much potential (voltage) and the wire has so little resistance electrons have no hard time passing from one side to other.
- Typical flashlight work with two AAA battery so total 3.0V and contains 4ohm resistance. With that formula, it will be 3.0/4 amper of current flowing through at any time.
- Same thing with bulbs used at homes. They are generally sold with Watt which is unit of power.
P = I * E (current * voltage)
- Considering home voltage is 120V and 100Watt bulb 100/120 is the current 0.83amp. Calculating resistance of bulb is E = I*R and R = E / I = 120 / (0.83) = 144ohm
- How bulb work is that they have tungsten wire that heats up and lit. It takes voltage from home infrastructure and other side is connected to some metal base. Resistance will allow the wire to heat up and give light. Of course, the bulb should be vacuumed otherwise this does not work.
- It is all good as soon as your best friend leaves the town and you have a new best friend that lives in the next house in the street.
- The whole system of communicating with the flashlight is gone since you can not send flashlight signals to him unless you put some kind of mirror setup.
- We now know how simple flashlight works with a simple combination of battery, wire, and bulb. We can set up the same thing through your house to your friend’s house. You just need longer wire and more powerful battery for that job since longer wire has more resistance and this means you need more voltage (potential).
- But you also need your friend messages so that he/she can talk back. The same setup would work but this time from his/her house to your house.
- Now when you send more codes by turning the switch on/off your friend can see these messages, same applies for him/her. We can cut the costs by removing some extra wires and connecting two setups into one. The wire that used by two setups called common.
- If we have some common between two setups you can get rid of common since it will not be used. We can replace it with ground or earth which is basically using earth as a conductor to move electrons from one side to another side. Seeing earth as giant conductor make sense negative end of the battery release electrons to the ground and in the other side, bulb gets electrons from earth again.
- To make the groundwork you need really good conductor buried into the ground with enough thickness. Copper wire would work.
- The earth is to electrons as an ocean to drops of water. Consider earth as the limitless source of electrons. You put electron from one place you get the electrons from other places.
Chapter 6 - Telegraphs And Relays
- If you take an iron bar and wrap it around with wire and give potential (basically voltage) it will create an electromagnetic field around it. Basically, it starts acting like a magnet.
- Morse utilized this idea and created a telegraph around this. On one side you push the button to send dot and dashes and on the other receiver side it will create a magnetic field and will produce sounds so that receiver can translate this to written form.
- But this setup has limits you cannot reach far distances because if you grow wire really longer it is hard to find voltage to pass the resistance created by the long wire.
- That’s where relay or repeater comes in. Before this people sit in between long distance and basically copy messages and relay them to another end in a manual way. But if you look closely they are basically mimicking the movements of one side. So instead of doing this way which is boring for a person to do they attached another button to end of the first one so that first one open middle one creates a magnetic field and pull the metal which mimics the behavior same way. This is called a relay or repeater.
Chapter 7 - Our Ten Digits
- Spoken language can be considered as code as it changes from culture to culture and for simple words like cat have different representations in different languages. But the same is not applicable for numbers as representation in writing is the same.
- First attempts of number systems date back to Roman numerals but real inventors of the current algebra are actually Hindu-Arabic. And after that, Arabic mathematicians bring the knowledge to Europe.
- Roman numerals are easy I state it is one, V states it is five as one hand, X is for ten two V or two hands, L for 50, C for 100 and D for 500 and M for 1000.
- Calculation of number is easy in roman you just have simple rules and add them up together to get the representation but multiplication and division are hard in roman.
- Going back to our current system it is based on position. So even though the number is the same if you change position it will have different magnitudes like 1 and 10 it is just a one place change.
- One thing other numbering systems do not have is zero which is important in the current system as it could be a placeholder and change the magnitude of the number significantly. The interesting thing about current number system is that 3+4=7 30+40=70 so it is all the same addition just magnitude changes depending on the position of the digit.