Programming Basics
Programming Basics
Binary Numbers
Quotient Remainder
123 / 2 61 1
61 / 2 30 1
30 / 2 15 0
15 / 2 7 1
7/2 3 1
3/2 1 1
1/2 0 1
= 11
Groups of bits
Once compiled, the binary program can The interpreter is required on the machine
be executed without compiler. where the program is executed.
Data in binary
How can we encode data in the real world into binary numbers?
+109 = 0 11011012
3.141592653589793
Floating point format has a finite precision, but digits of π run forever:
3.1415926535897932384626433832795028841...
But with only 64-bits we can only have precision up to a fixed digits
after decimal point: 3.141592653589793
(For more info: https://en.wikipedia.org/wiki/Double-precision_floating-point_format)
Text in binary
Letters and punctuations in human languages are encoded in binary using a
Character Encoding such as ASCII or UTF-8 (Unicode).
(source: https://simple.wikipedia.org/wiki/ASCII)
Images, audio & video in binary
Even for these complex data, the idea remains the same.
1 # Author: Deven
2 # My first program
3
4 # This is a comment on its own line & it will be ignored
5 print("Hello, world!") # str
6 print(123) # int
7 print(1.614) # float
We use comments to: