0
$\begingroup$

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?

$\endgroup$
6
  • 1
    $\begingroup$ Hi ! Sadly this is not a coding service, so any effort shown is a huge plus in your case. $\endgroup$
    – Sektor
    Jan 10, 2015 at 11:44
  • $\begingroup$ @Sektor updated question $\endgroup$
    – Cronovirus
    Jan 10, 2015 at 11:46
  • $\begingroup$ @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 . $\endgroup$
    – Cronovirus
    Jan 10, 2015 at 11:55
  • 1
    $\begingroup$ That's the spirit ! But before someone can help you - you gotta try to help yourself :) $\endgroup$
    – Sektor
    Jan 10, 2015 at 11:58
  • $\begingroup$ @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. $\endgroup$
    – Cronovirus
    Jan 10, 2015 at 12:04

2 Answers 2

4
$\begingroup$

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"

Compared to your result:

ConvertNumber[469785602403]

obfuscate[469785602403]
{"m", "a", "g", "i", "c"}

"magic"
$\endgroup$
0
$\begingroup$

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]]
$\endgroup$
9
  • 3
    $\begingroup$ 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) $\endgroup$
    – Nasser
    Jan 10, 2015 at 12:28
  • 2
    $\begingroup$ 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. $\endgroup$
    – Nasser
    Jan 10, 2015 at 12:41
  • 2
    $\begingroup$ Try ConvertNumber[32310939241583] $\endgroup$
    – Nasser
    Jan 10, 2015 at 12:50
  • 1
    $\begingroup$ You seem to be ignoring my answer. Does it not work as you desire? $\endgroup$
    – Mr.Wizard
    Jan 10, 2015 at 12:54
  • 3
    $\begingroup$ @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. $\endgroup$
    – Mr.Wizard
    Jan 10, 2015 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.