Convert Decimal to 256-base numeral system
Here is my solution how to convert a decimal number itto 256-base numeral system number. It's really simple actualy, if you know how to convert decimal to hex. After all 256 is 16*16. In this task вe use the following 256 digits:
A 0
B 1
…
…
Z 25
26 aA
27 aB
…
…
51 aZ
52 bA
53 bB
…
…
77 bZ
...
234 iA
235 iB
…
…
255 iV
We write the numbers as sequences of digits. The last digit of the number (the most right one) has
a value as shown in the above table. The next digit on the left has a value 256 times bigger than the
shown in the above table, the next digit on the left has 256*256 times bigger value than the shown in
the table and so on. Our task is to write a program to convert a decimal number into its corresponding
representation.
Input
The input data consists of a single integer number.
The input data will always be valid and in the described format. There is no need to check it explicitly.
Output
The output data consists of a single text line holding the result and should be printed at the console.
Constraints
• The input number is in the range [0…18 446 744 073 709 551 615] inclusively.
• Allowed work time for your program: 0.1 seconds. Allowed memory: 16 MB.
Examples
Input: 20
Output: U
Input: 30
Output: aE
Input: 280
Output: BY
Input: 1000
Output: DhY
You can find the solution see here. It's not fully tested but in general should be working. I know that it can be optimized using big letter/small letter char (char A to become 0 by substracting it's int representation and just adding small letters and so on).
Абонамент за:
Публикации (Atom)
Няма коментари:
Публикуване на коментар