Mathematics and Physics for Programmers

Edozié Izegbu
Learning to code
Published in
5 min readNov 15, 2015

Decimal Binary and Hexadecimal.

Base 2, Base 16 and Base 10

So Base 10 is not the best choice as an example to show as of course these articles are for programmers we want to talk about Binary. However there is nothing wrong with using Base 10 to describe numbers as you can easily tell whether a number is divisible by 2 or 5 (is the number even ? Does the number end in a 0 or a 5?) it is also relatively easy to tell whether a number is divisible by 3 or 9, (Is the sum of the digits a factor of 3? , Is the sum of the digits a factor of 9?), however it is less easy to find out whether a number is divisible by 4 or 7 (There is little or no correlation between the number itself and its divisibility by 4 or 7) .

So considering taking different bases and examining their uses. Base 12 this is used by the typical imperial system for measuring feet and inches, consider the advantages using this particular duodecimal system , you can easily find out whether a number is divisible by 2 ,3, 4 , 6,( all of which divide into 12, so you know that for instance 13 feet and 8 inches is divisible by 4 because an sum of feet will be divisible by 4 and 8 is also divisible by 4) . Base 60 is used in clocks , with hours and minutes. The babylonians used this base for general arithmetics , however they subdivided the base system into base 10 following its complexities. Base 360 is used in turns and degrees where 360 degrees is one turn. But we have to bear in mind that these bases require proper use as they predictably contain a lot of individual symbols and are difficult to keep track of sometimes. Despite its logicality Base 12 never caught on, except in limited ways.

Base 2 or Binary has particular advocates that make it useful across a wide set of uses . All numbers in binary are represented in powers of 2, for instance my age represented in binary would be 10101 ( 1 x 2⁰ = 1 , + 0 x 2¹ , + 1 x 2² = 4 , + 0 x 2³ , + 1 x 2⁴ = 16 … 1 + 4 + 16 = 21 .) . As you may learn in computer architecture 1 and 0 represent “on” and “off” respectively, this allows you to speak to the digital circuits which fits in perfectly with base 2.

While binary just requires 2 symbols to describe its numbers, hexadecimal uses 16 symbols , (A-F represent 10–15, and 0–9 are 0–9 ), so the hexadecimal number F1A would translate in decimal as (10 * 16⁰ = 10 +, 1 * 16¹ = 16 , + 15 * 16² = 3840…. 10 + 16 + 3840 = 3666). To convert this to binary you simply have to change each digit of the number into binary, so F1A would be 1111 0001 1010.

How computers represent numbers.

Seeing as binary is central to how all computers work , except of course Quantum computers but we will look at that later., it is important to see how computers represent numbers.

So because binary can conveniently be represented as 1s and 0s or ons and offs you can easily translate that to computers. As has been repeteadly said a computer thinks in numbers, and the numbers are represented as groups of switches, each switch is a binary digit or a bit . Numbers with 8 bits can represent 0 up to 255 and numbers with 32 can represent up to 4,294,967,295 , and 64 bits all the way up to 9,223,372,036,854,775,807 . Now usually one bit is left over to represent whether or not the number is negative so a number with 8 bits actually represents -127 to + 127 and a 32 bit -2,147,483,648 to +2,147,483,647 , lastly a 64 bit number can represent -2⁶³ — +2⁶⁴ . This is known as a “quad word”.

ASCII

On another note each character on your keyboard is represented as an ASCII code, which is numbered from 0–255 (8 bits). Therefore each letter in your string is measured with 8 bits, a string like “hello” will take up 5chars x 8bits = 40 bits of space , where a string like “overflow is not underflow” = 25 chars x 8 bits = 200 bits space taken up . ASCII also recognizes whitespace as a particular code.

Intel i7 4th gen

The computer’s environment is designed to perform mathematical calculations very very fast. It’s ability to do so is defined by the CPU’s ALU width, so a cpu bit with an ALU width of 32 bits can only handle individual numbers from -2³¹to +2³¹ (31 because 1 bit is designated to show whether a number is positive, or what Francis Masares despised, negative. ). 64 bit CPU’s can handle -2⁶³ to +2⁶³.

Since performing algorithms like multiplication or addition is so easy to a computer , Binary computations are especially fast.

Here is a psuedocode example of the binary addition ,

Now lets slow down and figure out exactly what is going on, we can say that this function is a good function because it just checks whether the numbers are the same or not “10” + “10” will give “100”.

So as you can see that it is pipsqueak easy for computers to manipulate integers. In fact it is so easy that it is the fundemental core of how the computer is a computer . The core of how it makes “decisions” is made on boolean logic, and , or and not. These combine binary or (boolean) digits together so you may manipulate them further.

and

The and boolean operator means that when digit A is compared with digit B the results are as follows in binary. So it implies that it can only be 1 , when both A and B are 1.

AND

or

OR

finally not

Multiplication in Binary is also easy, aything multiplied by two simply shifts the number along one , “10” [2] x 2 = “100” [4] . Now that I have been talkiing about integers in binary and basic arithmetic for a while. I think it is time that I start talking about fractions in my next article.

--

--