Nios/bcd2

From ASMBits

nios/decstr2Previous

Binary-coded decimal is a method to represent decimal numbers encoded into binary. It uses each group of 4 bits (which can normally represent numbers from 0 to 15) to represent one decimal digit (of values 0 to 9). Thus, the number 10 (or 0xa) is encoded in BCD as 0x10.

Write a function that converts a number into its BCD representation. You are guaranteed that the input number will be between 0 and 15.

Expected solution length: Around 6 lines.

Sample Input

10

Sample Output

0x10

Write your solution here

Upload a source file...