Solution: Number Base Conversion
Explore how to convert numbers between decimal and hexadecimal bases using various Ruby techniques. Learn manual conversion methods with arrays and hashes as well as built-in methods like to_s and to_i with base arguments to perform conversions effectively.
Decimal to hex
Explanation
Line 1: We create an array of characters representing hex values against the decimal numbers 0–15.
Line 4: The remainder—from the division of
numberby 16—is first converted to a hexadecimal string and prepended to the stringhexadecimal.Line 5:
numberis updated so that it stores the quotient from ...