• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Converting an array of ints into ascii

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have 8-9 digit integers generated as one unit, Is there a way to convert these into ascii? They're from an array.
It doesn't quite work.


 
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I assume you want to print the textual form of a number, so for example to turn the number 123 into the String "123"?

If so check out the Integer class. It has a method that will do what you want.

You don't seem to be using your array though, what is it for?

Also, arrays start at index 0, so if that for loop is for operating over the array it will have to be for indexes 0-9, not 1-10.
 
Gabe Evan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike. J. Thompson wrote:I assume you want to print the textual form of a number, so for example to turn the number 123 into the String "123"?
. . ..



I want the int 123 to be converted into ascii 049 050 051, and I've heard I have to use a char for it.
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A String is a collection of chars, so look in the Integer class for the method that will give you a String. If you really need the chars then you can get them from the String, but if all you want to do is print the number then you don't need the chars.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what are you doing with the digits array?

So you want to get the ASCII values of the individual digits? I think you might do well to turn the entire number into a String and look at its individual chars. Remember that a char is a number already.
Don't write a number as 049 or 050 because those don't mean 49 and 50.
 
Gabe Evan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:And what are you doing with the digits array?
. . .



The digits array generates 10 random numbers. I was hoping I wouldn't have to do them individually but I guess I do.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gabe Evan wrote: . . .
The digits array generates 10 random numbers. I was hoping I wouldn't have to do them individually but I guess I do.

You mean the Random object generates 10 numbers.

And please tell us what the smallest and the largest numbers you might generate are.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic