• 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

Receiving code of the char ($xx)

 
Ranch Hand
Posts: 103
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I'm wondering how can I receive "code" of the given char (keyboard code)

For example its:

$41 - A
$42 - B

$30 - 0
$31 - 1

and so on.

Thanks in advance for help.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll need to provide a little context. Are you talking about in a GUI, when a key is pressed? Or just some character that comes from wherever? Or something else?

And do you care about the key, or about the character? They're two different things.
 
Mathew Mintalm
Ranch Hand
Posts: 103
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to receive those numbers, for example there is String s = "test";

I will split this string into chars and I need to receive this number for every char.

By saying number i mean, for example:

A is $41

Thank you
 
Marshal
Posts: 28193
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
So probably you want the Unicode code point for the character, not its keyboard code. You get that simply by casting the char to an int, like so:

And what's that dollar sign in your question for?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:
And what's that dollar sign in your question for?



I've seen contexts where a dollar sign indicates hex notation, although it's been a LONG time.

And since 'A' = 65 = 0x41, I figure that's what he meant by $41.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:So probably you want the Unicode code point for the character, not its keyboard code. You get that simply by casting the char to an int, like so:



And to get the hex representation:

 
Mathew Mintalm
Ranch Hand
Posts: 103
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for replys.

But the point is that I'm receiving wrong values (I mean different than those provided by my teacher)

My previous lesson was about "encryption", and after every lesson he is giving me different task, like write program in my language (which is going to be used during my school secondary school certificate - IT)

For example for 'A' im receiving 65, and my teacher said its $41 (this dollar doesn't really matter, I need just number for calculations)
 
Paul Clapham
Marshal
Posts: 28193
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
Perhaps in your teacher's notation, the "$" indicates that the following digits are hexadecimal?
 
Mathew Mintalm
Ranch Hand
Posts: 103
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you were right, now it works as it should, thanks everyone for help.
 
Sheriff
Posts: 22783
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
$ is the Visual Basic (ugh) HEX symbol, and it's probably used in other languages as well. Apparently your teacher has a history in one of these languages before he started Java. Tell him that Java uses 0x instead and that he should consider switching to prevent confusion; you may even get a little extra credit for it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic