# Decimal-to-ASCII conversion

I have to write a program that converts a number (decimal notation) to an ASCII string.

For example, x = 26728 (or 0x6868) and the string is "hh".

I wrote this, but it seems that it is not the solution:

toMessage[n_] := FromCharacterCode[IntegerDigits[n, 100] + 31]


How can I do it?

• Hi ! Sadly this is not a coding service, so any effort shown is a huge plus in your case. Jan 10, 2015 at 11:44
• @Sektor updated question Jan 10, 2015 at 11:46
• @Sektor a clarification.. I thought that this was a place to help people in need. I asked how do you make a convert decimal-ascii , I did not ask you to tell me how to go to the moon . Jan 10, 2015 at 11:55
• That's the spirit ! But before someone can help you - you gotta try to help yourself :) Jan 10, 2015 at 11:58
• @Sektor If i ask it here it means that i'am not able to do it (My solution just concat number..). I'm noob with mathematica and i ask stupid things, but given that i don't have a teacher i need to ask someone. Jan 10, 2015 at 12:04

This may be what you want. Be warned that it will include non-printable (control) characters.

obfuscate[n_Integer] := FromCharacterCode @ IntegerDigits[n, 256]

obfuscate[26728]

"hh"


ConvertNumber[469785602403]

obfuscate[469785602403]

{"m", "a", "g", "i", "c"}

"magic"


I found the solution

MakeList[0] = {};
MakeList[num_Integer] := Append[MakeList[Quotient[num, 256]], Mod[num, 256]]
ConvertNumber[num_Integer] := FromCharacterCode /@ MakeList[num]


then

StringJoin[ConvertNumber[310939241583]]

• did you test it? ConvertNumber[3277] should return " M" but it does not. (ps. do not use UpperCaseFirstLetter, these are meant for Mathematica own functions only) Jan 10, 2015 at 12:28
• But that is not what you said you wanted. You said "For example x = 26728 (or 0x6868) and the string is "hh", which means I can give your program any number(s) and it should work. If all you want to convert was one single number, you should have said so. ps. 32 is the space character. Jan 10, 2015 at 12:41
• Try ConvertNumber[32310939241583] Jan 10, 2015 at 12:50
• You seem to be ignoring my answer. Does it not work as you desire? Jan 10, 2015 at 12:54
• @Cronovirus This is not a contest. You asked for help; I attempted to provide it. It would be appropriate to at least let me know if it does what you wanted. Jan 10, 2015 at 13:02