course content

Course Content

Numeral Systems 101

Deciphering ChallengeDeciphering Challenge

There is another commonly used numeral system called hexadecimal. If you learn web programming or something related to that, you should come across RGB Color Codes Chart that is implemented using hex(hexadecimal system) to help computers define different colors. Red -> #FF0000 White->#FFFFFF Yellow->#FFFF00 and the same representation for each color.

Hex is a representation of 4 bits. Computer professionals even consider reading the hexadecimal number easier than decimal one and binary. As I said previously it is a beautiful way of storing data not in a binary way, but to group it; hence, hexadecimal numerical system is implemented.

This one consists of 16 digits, 0->0 1->1 2->2 3->3 4->4 5->5 6->6 7->7 8->8 9->9. I suppose you start guessing the outcome of this sequence and involve 10 as the 10th number of this continuity, but you will be taken aback because 10->A 11->B 12->C 13->D 14->E 15->F But to convert it to decimal one, you should identify the dictionary, due to the reason that dictionaries are a superior way to hold information with a key. In the previous steps all of the keys conformed to numbers, but here due to the letters dictionary should be implemented.

Rule

I reckon that you are familiar with different algorithms so it seems to me that you can guess that here(in the hexadecimal numeral system) we are going to multiply each digit by 16 raised to the power of index. Obviously, we can not multiply the letter; therefore, we should find the math for it. For instance ABC10-> (A)10x16^4+(B)11x16^3+(C)12x16^2+1x16^1+0x16^0=655360+45056+3072+16+0=703504

Task

I appreciate your desire to study, way to go! Write the code that will decode the number 'CAFE' from the hex numeral system to decimal. Follow this algorithm:

  1. Print the hexadecimal number.
  2. Assign 0 to the decimal_number variable.
  3. Define the variable power for storing the power and assign 0 to it.
  4. Define the loop which iterates through the hexadecimal_number string.
  5. Get the very last character of hexadecimal_number string.
  6. Raise 16 to the relevant power and multiply it by the digit.
  7. Increase power by 1.
  8. Remove the last character of the string hexadecimal_number.

Everything was clear?

Section 3. Chapter 1
toggle bottom row