Showing posts with label binary. Show all posts
Showing posts with label binary. Show all posts

Non-integer numbers conversion - Computational Mathematics CM1015

Non-integer numbers conversion


Example:

$ 17.375_{10} = 1*10^1 + 7*10^0 + 3*10^{-1} + 7*10^{-2} + 5*10^{-3} = $
$ = 10 + 7 + \frac{3}{10} + \frac{7}{100} + \frac{5}{1000} $

How do you convert decimal fractions to binary?


You convert the whole integer numbers separately:

$ 17_{10} = 10001_2 $

Then you convert fractional part 0.375_{10}:
Multiply by 2, see if you have a whole number 1:
0.375*2 = 0.75 = 0 + 0.75 
0.75*2   = 1.5   = 1 + 0.5 Multiply the remainder of 0.75
0.5 *2    = 1.0   = 1 + 0.   STOP

$ 0.375_{10} = 0. \color{red} {011}_2 $ 
$ 17.375_{10} = 10001. \color{red} {011}_2  $

How to convert a binary fractional number to a base 10 number?

$  10001. \color{red} {011}_2  = 1*2^4 + 0*2^3 + 0*2^2 +  0*2^1 + 1*2^0 + \color{red} { 0*2^{-1} + 1*2^{-2} + 1*2^{-3} }$
$  10001. \color{red} {011}_2  = 1*16+ 0*8 \ + 0*4 \  + 0*2 \ + 1*1 + \color{red} { 0* \frac{1}{2} + 1*\frac{1}{4} + 1*\frac{1}{8} }$
$ 10001. \color{red} {011}_2  = 16 + 1 + \color{red} { \frac{0}{2} + \frac{1}{4} + 1*\frac{1}{8} }$
$ 10001. \color{red} {011}_2  = 17 + \color{red} {   \frac{3}{8}   } $ 
$ 10001. \color{red} {011}_2  = 17. \color{red} { 375}_{10} $


In general:

$$ A_n A_{n-1} A_{n-2} ... A_0 . C_{-1} C_{-2} ... C_{-k} $$

for base b, and position n and k,

In decimal units corresponds to:


$$ A_n * b^n + A_{n-1} * b^{n-1} + ... +  A_0 * b^0 + C_{-1} * b^{-1} + C_{-2} * b^{-2} + ... + C_{-k} * b^{-k}   $$


Practice:
see reference 2

Convert the decimal number 11.625 into binary

$ 11 \color{red} {.625}_{10} $
$ 11_{10} = 1011_2 $
$  \color{red} {.625}_{10} = $
Multiply by 2 and carry over the remainder:
2*0.625 = 1.25 = 1 + 0.25
2*0.250 = 0.50 = 0 + 0.50
2*0.500 = 1.00 = 1 + 0.00 // STOP

$ 11 \color{red} {.625}_{10} = 1011. \color{red} {101}_2$






What is the decimal number 0.03125 in binary?

$ 0.03125_{10} = ? $ in  binary 
Multiply by 2 and carry over the remainder:

2 * 0.03125 = 0.0625 = 0 + 0.0625
2 * 0.06250 = 0.1250 = 0 + 0.1250
2 * 0.12500 = 0.2500 = 0 + 0.2500
2 * 0.25000 = 0.5000 = 0 + 0.5000
2 * 0.50000 = 1.0000 = 1 + 0.0000 // STOP

$ 0.03125_{10} = 0.00001_2 $





Operations with binary numbers

See reference 3

Addition of binary numbers


$ 101_2 + 111_2 = ? $

$ 1110 $ \\ carry-over numbers
$ 0101_2 + $
$ 0111_2 = $
$ \overline{1100}_2  $

$ = 1*8 + 1*4 + 0*2 + 0*1 = 12_{10} $

double-check in decimal: 5 + 7 = 12 
Q.E.D.

Subtraction of binary numbers


$ 110_2 - 101_2 = ? $


$ 110 - $ \\ 6 decimal
$ 002 -  $  \\ promoted numbers
$ 101 = $ \\ 5 decimal
$ \overline{0 0 1}_2 $ \\ 1 decimal

Multiplication of binary numbers

0*0 = 0
1*1 = 1
1*0 = 1


Exercise:

1111 * 11 = 101101
15 * 3 = 45





Division of binary numbers




Number bases webinar video

See reference 4






"The only time you are getting better is when you are stuck.
- So, embrace being stuck! "



Extra video: numbers 1

See reference 5

  • prime numbers
  • highest known prime number $ 2^{77232917} - 1$
  • exponentials
    • $ x^0 = 1 $
    • $ x^1 = x $
    • $ x^2 = x * x $
    • $ x^{-1} = \frac{1}{x} $
    • $ x^{-2} = \frac{1}{x*x} = \frac{1}{x^2} $
    • $ x^{-n} = \frac{1}{x^n} $



    Extra video: numbers 2

    see reference 6

  • base ten fractional
  • what is the lowest base you can have
    • base 2
  • conversion exercises




see reference 7




See reference 8







References

  1. https://www.coursera.org/learn/uol-cm1015-computational-mathematics/lecture/wrj47/non-integer-numbers-conversion
  2. https://www.coursera.org/learn/uol-cm1015-computational-mathematics/quiz/QW8GL/topic-1-lesson-3
  3. https://www.coursera.org/learn/uol-cm1015-computational-mathematics/lecture/0qco4/operations-with-binary-numbers
  4. https://www.coursera.org/learn/uol-cm1015-computational-mathematics/lecture/y71es/number-bases-webinar-video
  5. https://www.coursera.org/learn/uol-cm1015-computational-mathematics/lecture/K02pr/extra-video-numbers-1
  6. https://www.coursera.org/learn/uol-cm1015-computational-mathematics/lecture/lHwNt/extra-video-numbers-2
  7. https://docs.google.com/spreadsheets/d/19zWX5qNcfVwG37VUSi0aeCMfNSOwhq1MMNtdwguyk5k/edit#gid=0
  8. https://calculator.name/baseconvert/quinary/decimal/1212



As an Amazon Associate I earn from qualifying purchases.

Computational Mathematics

 


https://www.coursera.org/learn/uol-cm1015-computational-mathematics/supplement/Ok8Zg/introduction-to-computational-mathematics-course


handle numbers in any base and perform operations with binary numbers. You will learn about sequences, recursion and series, basic trigonometry and geometry.

You will also be introduced to functions, their different types, how to plot them and how to study their properties through basic calculus, limits and derivatives. You will also be introduced to linear algebra, vector spaces and the basic concepts of combinatorics, statistics and probability.

How to pass?

https://www.coursera.org/learn/uol-cm1015-computational-mathematics/supplement/57Ggy/how-to-pass-the-course




Number Bases

https://www.coursera.org/learn/uol-cm1015-computational-mathematics/lecture/nPHpG/introduction-to-number-bases-conversion-to-decimal


For any number base b, written with positions n such as:

$$ a_n a_{n-1} a_{n-2} ... a_0 $$

the conversion to decimal will be:

$$ a_n * b^n +  a_{n-1}* b^{n-1} + ... +  a_0*b^0 $$

Binary


  • 0 - 00000000 
  • 1 - 00000001 
  • 2 - 00000010 
  • 3 - 00000011 
  • 4 - 00000100 
  • 5 - 00000101 
  • 6 - 00000110 
  • 7 - 00000111 
  • 8 - 00001000



$ 1001_2 \\ = 1*2^3 + 0*2^2 + 0*2^1 + 1*2^0  \\ = 8 + 0 + 0 + 1 \\ =  9_{10} $


$ 100 101 011_2 = \\
= 1*2^8 + 0*2^7 + 0*2^6 + 1*2^5 + 0*2^4 + 1*2^3 + 0*2^2 + 1*2^1 + 1*2^0 = \\
= 1*256 + 0*128 + 0*64 + 1*32 + 0*16 + 1*8 + 0*4 + 1*2 + 1*1 = \\
= 256 + 32 + 8 + 2 +1 = \\ = 299_{10} $




Decimal

count to 9, then zero add 1 in front to make 10. and so on

$ 127_{10} \\ = 100 + 20 + 7 \\ = 1*10^2 + 2*10^1 + 7*10^0 $


Hexadecimal (base 16)


0, 1, 2, ..., 9, A, B, C, D, E, F

$ 1F_{16} =  1*16^1 + 15*16^0 =  16 + 15 =  31_{10} $


Sexagesimal

 - Sumerians, Babylonians, angles, time, etc.


Method of repeated division









As an Amazon Associate I earn from qualifying purchases.

apt quotation..