Base 2: Binary numbers only consists of digits 0 and 1.
Base 10: Decimal numbers only consists of digits 0-9.
Base 16: Hexadecimal (or Hex) numbers only consists of digits 0-9 and a-f.
Converting between Binary <–> Decimal
Converting between Hex <–> Decimal
Converting between Binary <–> Hex
Video Addendum
true and false are actually equivalent to 1 and 0 respectively.
Assignment
Fill out tables 0-3 below. Work out everything on paper (no calculators or computers allowed). If you feel shaky, Tables 4-6 provide supplemental practice.
Fill out table 7.
Write a function which returns the 3rd digit of the input. For example, an input of 9872 would return 9. An input of 1 would return 0 as 001 is the same value as 1. Hint is below.
Write a function which takes in two inputs: A, B. (choose better names as you see fit). Return the B’th digit of A. For inputs: A=8972 and B=2, return 9 as 9 is the 2nd digit. The 0th digit is 2, 1st digit is 7 and 3rd digit is 8.
Ask the user to input an unsigned int. Check if the user input a valid binary number. For example, 912 is not a valid input as 9 or 2 are not binary digits. If its a valid binary, print out the decimal (not float, but rather Base 10) value of the number they input. For example, input 1000 would print out 8 as Base 2 1000 is Base 10 8.
Hint #3
399 / 100 == 3 in C++ because remember / only returns whole number part when working with the int type.
Hint #3
How can the % operator help?
Samples
Table 0
Short hand
Decimal Value
Binary Value
Hex Value
20
21
22
23
24
25
26
27
28
29
210
Table 1
Decimal Value
Binary Value
Hex Value
432
773
650
819
878
824
408
772
650
533
345
232
34
401
230
620
145
404
790
861
238
946
558
168
264
260
497
489
132
120
Table 2
Decimal Value
Binary Value
Hex Value
0b1010000110
0b101111000
0b1110111101
0b1001010000
0b1100010111
0b100101000
0b1000110011
0b1101101001
0b1000000100
0b1001100011
0b1000100111
0b10000100
0b1010010111
0b1101110101
0b1100101110
0b1010010100
0b1100010101
0b11100110
0b1011110101
0b110010010
0b101101111
0b1001011
0b1101101
0b1110001110
0b10010000
0b101110111
0b100001111
0b1101111100
0b1011100
0b11010000
Table 3
Decimal Value
Binary Value
Hex Value
0x3E1
0xB6
0x44
0xAE
0x64
0x2C
0x1B0
0x157
0x1B1
0x297
0x1D8
0xBA
0x23E
0x1F0
0xA6
0xA1
0x34A
0x2FE
0x36A
0x36E
0x24E
0xAA
0x32B
0x2E1
0x162
0x11
0x343
0x209
0x1EC
0x138
Table 4
Decimal Value
Binary Value
Hex Value
437
351
432
392
742
39
216
906
251
869
245
126
714
823
794
325
419
958
701
312
674
825
866
274
91
574
791
975
419
582
103
360
760
176
194
622
595
493
260
885
981
585
58
2
664
644
630
375
603
608
102
320
585
479
419
294
212
402
535
168
490
907
146
843
692
776
530
726
925
655
Table 5
Decimal Value
Binary Value
Hex Value
0b1110101000
0b1011001110
0b1010000001
0b10110001
0b1101101000
0b1011100110
0b11001111
0b1111010111
0b1000101101
0b1101111101
0b1000100000
0b1101010101
0b1101000000
0b101010110
0b1111111
0b100011100
0b1101001111
0b110001011
0b1001011000
0b1010001000
0b101111010
0b1111001010
0b100011000
0b1100100111
0b1111011110
0b10100110
0b1101111111
0b1101000000
0b1010001011
0b111000100
0b1110111100
0b100000101
0b10000000
0b1110101100
0b1010111000
0b10001100
0b1101110111
0b1010110
0b101101
0b11100011
0b100110110
0b1101111100
0b1110010010
0b101101001
0b1011110000
0b101000001
0b1110111100
0b1110111010
0b100011001
0b100011001
0b1010010
0b1111010111
0b1000111
0b1110010101
0b11000011
0b1010001000
0b1111100001
0b110000110
0b1111
0b1001101
0b101111010
0b1001010000
0b110110010
0b1000000
0b1101101110
0b110100110
0b111110110
0b1101011001
0b10
0b101111101
Table 6
Decimal Value
Binary Value
Hex Value
0x26A
0x1D9
0xB1
0x128
0x355
0x373
0x2E3
0x65
0x3B
0xFF
0x18C
0x1BC
0x3C4
0x37E
0x15B
0x2F8
0xA4
0x92
0x27
0x309
0x3D7
0x259
0xCB
0x118
0x3E2
0xF6
0x37C
0x2F6
0x2B6
0x3DB
0x140
0x2A1
0xB6
0x39A
0x322
0x164
0x213
0x1E4
0x1B1
0x374
0x2C6
0x371
0x1D5
0x362
0x231
0x111
0x21B
0x2F8
0x15C
0x30B
0x3AA
0xBA
0x320
0x2B7
0xE1
0x2D8
0x1B5
0x140
0x131
0x363
0xB9
0x158
0x3A5
0x3E
0x3A7
0x4A
0x171
0x189
0x2EE
0x2C6
Table 7
A
B
A + B (in Hex)
0x331
0x3B6
0x123
0x2D4
0x169
0x29D
0x2DA
0x29E
0x1E3
0x2B1
0x8
0x200
0x35C
0xD7
0x23B
0x1DA
0x23A
0x119
0x3CB
0x2A8
End of Assignment Checklist
I finished all the assignments.
I shared my assignments with others.
I provided feedback for assignments of at least 2 others.
I addressed the feedback from others and thanked them for the review.