• 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

ascii decimal conversion problem

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need a way to take the output of a JSpinner with a custom value list - 00, 01, 02, etc, to 10 - and convert that to an ASCII decimal sequence. For example, "00" would like "48 48" and so on. I don't know how to do that conversion - a hint or a link would be helpful.

The second part of the problem comes when those new values have to be placed into the second and third slots of the example sequence below:



byte[] arr = {(byte)33, (byte)48, (byte)48, (byte)66, (byte)67, (byte)78, (byte)49, (byte)13};



Any help or advice is always appreciated. Thank you!
 
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This looks like the means towards a goal. What is your goal?
 
Scott A Burch
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The goal is to slide that array through a serial port via an outputstream to control an external device. My preliminary model works only when the array is "hard coded". I have to find a way for it to be more flexible so that a user can select a network of devices to control.
 
Scott A Burch
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the block in question:


 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am also missing why solving that problem reduces to the question you posted. If it were me I would just put a suitable list of objects into the spinner's model and just use data from those objects. Or something like that... I didn't read your requirement all that closely.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are two smaller problems at hand here:
1) getting the JSpinner to show values from 00 to 10.
2) converting the current value to two digits.


For problem 1 you can use a SpinnerListModel if your inputs are limited in number. Otherwise, use a SpinnerNumberModel and a JSpinner.NumberEditor to display the value using two digits, then get the value back and use a NumberFormat to format it to two digits.

For problem 2 you can, with a two character String, simply get the two chars (charAt) and convert them to int to get the ASCII value - as long as the chars are digits of course.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't double-click the Code button. Make sure your code is between a [code] begin tag and [/code] end tag.
 
Scott A Burch
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the code tag tip.

My JSpinner actually works fine right now. I am using the ListModel and just populated the list with the items "01" "02" etc, up to "10". Thanks for the info on JSpinner NumberEditor; I was introduced to spinners on the fly for this project.

charAt should do the trick for decimal conversion.

I'll start a new thread for the next problem I have ... ha!

thanks to all again.
reply
    Bookmark Topic Watch Topic
  • New Topic