This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java Micro Edition and the fly likes Accessing Internal Represenation of a character Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Reply Bookmark "Accessing Internal Represenation of a character" Watch "Accessing Internal Represenation of a character" New topic
Author

Accessing Internal Represenation of a character

sur manickam
Greenhorn

Joined: Dec 27, 2008
Posts: 6
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

Joined: Jun 25, 2001
Posts: 14475
    
    7

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;


Customer surveys are for companies who didn't pay proper attention to begin with.
sur manickam
Greenhorn

Joined: Dec 27, 2008
Posts: 6
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 ?
 
 
subject: Accessing Internal Represenation of a character
 
Similar Threads
String and boolean memory
Declaration difference
Serialised session size
WA #1.....word association
split method in java