Number Systems

Israel Gbati
A free video tutorial from Israel Gbati
Embedded Firmware Engineer
4.1 instructor rating • 45 courses • 59,417 students

Learn more from the full course

ARM Assembly Language From Ground Up™ 1

Build over 50 Assembly Programs - ARM Instruction Set, Peripheral Driver Development, Algorithms, DSP routines etc.

15:05:27 of on-demand video • Updated September 2020

  • Master the ARM Instruction Set
  • Master the Thumb and Thumb-2 Instruction Sets
  • Understand the ARM Design Philosophy
  • Understand RISC Architecture
  • Master creating Data Structures in Assembly
  • Master creating State Machines in Assembly
  • Master building complex Algorithms in Assembly
  • Master writing hardware Drivers in Assembly
  • Be able to create Lookup Tables and Jump Tables in Assembly
  • Be able to understand and apply the IEEE- 754 Floating point standard
English Hello fellas welcome back. Like we mentioned previously computers operate internally with transistors acting as switches and this is the combinational logic used to build the adders, the multipliers, the dividers etc. Switches like any switch you are familiar with understands two states on or off. The binary system therefore offers itself to use in computer systems more easily than other number systems. The binary system is also known as the BASE 2 system and numbers in the BASE 2 are centered on the idea that each digit now represents a power of two. In the base 10 system that we use in our daily lives, allowable numbers are 0 through 9. So if you were to count the number of pens in a box you would say 0 1 2 3 4 5 6 7 8 9. And then you run out of digits therefore you place a 1 in the place of the 10 in the ten's position to indicate you've counted this high already and begin using the old digits again 11 12 13 14 15 16 17 etc.. Now imagine that you have only two digits which count zero or one. To count the same set of pens you would say 0 1. And then you are out of digits. We know the next value is 2 in BASE 10 but in BASE 2 we place a 1 in the two's position and then we keep counting 1 0 , 1 1 and then we run out of digits again. Another marker is then added 1 0 0. Then we continue 1 0 1 and so on and so forth. This table over here shows an example of binary counting from 0 to 15 or from 0 0 0 0 to 1 1 1 1. You can pause the video and examine this carefully if you're not very familiar with binary counting or if you want to revise. Now let's see how to convert binary numbers to decimal numbers when we write numbers in a different BASE system which is in BASE 10, we have to add the subscript indicating the BASE. So we will write a base 2 a number like this: 1 1 0 1 0 1 BASE 2. To convert this number to BASE 10 We simply need to compute this: 1x(2^5)+1x(2^4)+0x(2^3) etc.. think you can see the order here. We take this number here, the actual number, multiplied by BASE 2 and then the BASE 2 is raised to the position of the number. So we count form here. This is 0 1 2 3 4 5. So then, (2^0)x1 , (2^1)x0, (2^2)x1, (2^3)x0, (2^4)x1, (2^5)x1 Of course this is one. And then we add all of it. And then we produce the outcome. So that's very simple. This is how we convert from binary to BASE 10. As you would agree it will be rather frustrating to be staring at 1s since 0s all day. Therefore better and much shorter choices for representing numbers were adopted. The BASE 8 or the octal system was used a bit in the early days. The BASE 16 or the hexadecimal system is very popular and currently in use. In the BASE 16 we count from zero to 15. However when we get to the number 10 we start representing the numbers using the first eight English alphabet. So in BASE 16 we will count 0 1 2 3 4 5 6 7 8 9 A B C D E F convert from BASE16 to BASE 10 is just the same as we did for conversion from BASE 2 to BASE 10. Let's see we wish to convert this number over here. 0xA5E9 to BASE 10. This number is BASE 16 we wish to convert it to BASE 10. So we simply compute this like we did before. We just examine the place of each digit. This first digit. 9's position is 0. E's position is 1, 5's position is 2, A's position is 3. Therefore (16^0)x9, (16^1)x14 E represents 14 And then once we compute this we just get the sum of it. And then we have our value in decimal form. Your assignments of the end of this lesson will be to learn how to convert BASE 10 to BASE 16. This table over here shows them the first 16 numbers represented in the three number basis we have just studied. If you observe carefully you will realize that four binary digits us one hexadecimal digit. This is very powerful. This allows us to massively shorten the length of addresses and instructions. For instance this long binary number can be represented like this A5E9. This binary number 0b 1010 0101 1110 1001, in hexadecimal is as simple as A5E9 and this is the same number we just converted to decimal form and the "0b" here is used to indicate the number is binary. Up here the "0x" we use to indicate the number is hexadecimal. Hexadecimal numbers are written starting with "0x" and then the number. Binary numbers are often written using "0b" and then number. So, hexadecimal form, binary form. One hexadecimal digit equals four binary digits. This is 9 -> 1 0 0 1 If we check 9 over here it's indeed 1 0 0 1. This is A->1010 If you check A over here it is 1 0 1 0. So, this is how we're going to be writing our code. We write in hexadecimal form. If there is a mistake or if there's something we don't understand we just expand into the binary form and we see whether indeed it accesses the particular bits in register that we are trying to access.