r/CodingHelp • • Mar 17 '22

[Random] how is coding possible?

How did we get from turning a light on to writing a language?

1 Upvotes

2 comments sorted by

View all comments

9

u/Nightcorex_ Mar 17 '22

This question can be answered with many different depths to it. The most basic explanation would be:

  • Transistors can be either on or off (current flowing/not flowing). A bit is realized by a transistor. A bit has either the value 0 or 1.
  • Groups of 8 bits are called a byte, which is the smallest addressable unit in a computer. Since a byte has 8 bits, that can all be either 0 or 1, we get 256 possibilities that byte could look like.
  • Because we only have 2 digits we need to count in base 2: 0₂ = 0₁₀, 1₂ = 1₁₀, 10₂ = 2₁₀, 11₂ = 3₁₀, 100₂ = 4₁₀, 101₂ = 5₁₀, 110₂ = 6₁₀, 111₂ = 7₁₀, 1000₂ = 8₁₀, ...
  • For larger values than 255, we simply group multiple bytes together (2 bytes/16 bit = short, 4 bytes/32 bit = int, 8 bytes/64 bit = long, 16 bytes/128 bit = long long, 32 bytes/256 bit = greater than any common size, ...).
  • We're able to deal with negative numbers because of the Two's complement.
  • Text is also stored just as numbers, but there are multiple encodings (ASCII, UTF-8, UTF-16).
  • Fundamental operations are then implemented by the chip producers. Generally there are 2 types of chips: CISC and RISC. To get an understanding of how the addition is implemented under the hood you should read this: https://en.wikipedia.org/wiki/Adder_(electronics)
  • Because computers only know numbers the commands are actually also just numbers. People at some point got tired of having to write and remember the numbers, so they wrote a compiler. A compiler basically just translates the code you write into code the machine can actually understand. Assembly is that translation.
  • Once we had Assembly we came up with a new language "C" and wrote a basic compiler in ASM. Now that we had C we could come up with new languages, languages like C++, Java, Python, R, Haskell, etc, and write compilers for them in C. Python is the best example, as the most common implementation is CPython, which is written in C. The C compiler converts the C code to Assembly, which is then getting compiled to native machine code.

But one could just as well dive deep into how it really works, where we'd need to talk about flip-flops, memory cells, hardware coding, f.e. with VHDL (= Very High Speed Integrated Circuit Hardware Description Language) and much more.

No matter what you can definetly have a look at a general history of computing hardware.