Home > Net >  how to convert Decimal numbers to ASCII?
how to convert Decimal numbers to ASCII?

Time:05-27

Hello i want to convert a decimal number to ASCII so this the code i parse my string to int then i call the function String.fromCharCode to convert the int to decimal . But it doesn't work any help ! thanks

 String payload ="47, 50, 48, 50, 50, 59, 49, 52, 58, 51, 52, 59, 48, 55, 47, 58, 5";
 print (payload);
for (var i = 0; i < payload.length; i  )
          {
            print (payload[i]);
            data = String.fromCharCode(int. parse(payload[i]))   data ;
          }
print(data);

CodePudding user response:

Try this one:

for(int i=65; i<=90; i  ){
  print("${String.fromCharCode(i)}");
}

CodePudding user response:

okay so this how it works for me

 String payload ="47, 50, 48, 50, 50, 59, 49, 52, 58, 51, 52, 59, 48, 55, 47, 58, 5";

final splitted = payload.split(',');

for (var i = 0; i < splitted.length ; i  )
          {
            print (splitted[i]);
            data = String.fromCharCode(int.parse(splitted[i]))   data ;
          }
print(data);

CodePudding user response:

You first need to split your String into tokens, parse those individually, and then create a String from the parsed integer values.

void main() {
  String payload =
      "47, 50, 48, 50, 50, 59, 49, 52, 58, 51, 52, 59, 48, 55, 47, 58, 5";
  var s = String.fromCharCodes(payload.split(',').map(int.parse));
  print(s);
}

I'll also point out that an ASCII value of 5 (ENQ) is very suspect.

  • Related