This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing Internal Represenation of a character

 
sur manickam
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,

Could anyone guide me in this regard.

When we declare and store a character in java, it is represented in the memory as binary, is it possible to access and change the bits from the memory directly. To get more idea about the same which topic should I read.

Thanks.
 
Tim Holloway
Saloon Keeper
Posts: 18363
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java Mobile and regular Java are identical in this regard, so you could have asked the question in the Java (Beginner) forum and gotten the same reply, but here it is:

Java uses Unicode as its internal character representation. To store in any other form (such as ASCII or EBCDIC), you'd have to store the data in a byte object and not a character/string object.

Java allows upcasting characters to integers. Once you have the value as an integer, you can do all the usual integer and bit operations on that integer. To return the data to character form, you have to downcast it again.

So:

final int HEX10 = (int) 'A';
int hex12 = ( ((int) 'C') - HEX10 ) + 10;
 
sur manickam
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java uses 16 bits for each character. Low-order 8 bits stands for the ascii value. Is it possible to store some extra bits in the high-order 8 bits ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic