• Post Reply Bookmark Topic Watch Topic
  • New Topic

Receiving code of the char ($xx)  RSS feed

 
Ranch Hand
Posts: 103
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
  • 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
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
 
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you were right, now it works as it should, thanks everyone for help.
 
Sheriff
Posts: 21137
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!