Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Last active October 3, 2018 00:10
Show Gist options
  • Save harrisonmalone/715c392a487134b7db66ff2d1b77a935 to your computer and use it in GitHub Desktop.
Save harrisonmalone/715c392a487134b7db66ff2d1b77a935 to your computer and use it in GitHub Desktop.

Morning ruby drills

The test in the morning was to get you drilled in the basics of ruby. Refer back to it and make sure you practice as often as you can!

Binary numbers and bases

Today we looked at binary numbers and the way in which they work in discrete maths. We also touched on different number systems such as base-2, base-10 and base-16. Base-10 has 10 digits (0,1,2,3,4,5,6,7,8,9) and base-2 has 2 digits (0,1). Base-16 has a weird alphabet thing going on. The following was my working out to some of the day's challenges.

Convert 11201 from base 3 to decimal

3 * 4, 3 * 3, 3 * 2, 3 * 1, 3 * 0
81	27	9	3	0
1       1       2       0       1
81      27      18      0       1
=> 127
Convert 103245 from base 6 to decimal

6 * 5   6 * 4   6 * 3   6 * 2    6 * 1    6 * 0
1         0       3       2        4        5
7776     1296    216      36        6       1
7766      0      648      72        24      5
=> 8525
Convert 3123012 from base 4 to decimal

4 * 6 4 * 5 4 * 4 4 * 3 4 * 2 4 * 1 4 * 0
3       1     2     3     0     1     2
4096  1024   256    64    16    4     1
12288   1024  512   192   0     4     2
=> 14022
Convert 123456 from decimal to base 2

2 ** 16         1
123456 -         
65536
--
2 ** 15         1
57920 -
32768
--
2 ** 14         1
25152 - 
16384
--
2 ** 13         1
8768 -
8192
--
2 ** 12 X       0
2 ** 11 X       0
2 ** 10 X       0
2 ** 9          1
576 -
512 
--
64 
--
2 ** 8 X        0
2 ** 7 X        0
2 ** 6          1
64 -
64 
--
0
--
2 ** 5 X        0
2 ** 4 X        0
2 ** 3 X        0
2 ** 2 X        0
2 ** 1 X        0
2 ** 0 X        0
=> 11110001001000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment