Does java has data type for hex value?

A

Abby

In C, I can use unsigned char to define hex value. Plz see below:

unsigned char c = 0x01;

Does java has this data type or something similar? I have a reason
that I need to declare many hex values inside the program. I'm
thinking about migrating from C to Java. Please give me some advice.
Thank you so much.
 
M

Marco Schmidt

Abby:
In C, I can use unsigned char to define hex value. Plz see below:

unsigned char c = 0x01;

Does java has this data type or something similar? I have a reason
that I need to declare many hex values inside the program. I'm
thinking about migrating from C to Java. Please give me some advice.

You can use literals in hexadecimal notation in Java as well:

char c = 0x01;

Also works with byte, short, int and long.

I found
<http://www.clarkson.edu/~jets/cs242/fa01/Examples/literals.html> with
more examples.

Regards,
Marco
 
L

Lee Fesperman

Abby said:
In C, I can use unsigned char to define hex value. Plz see below:

unsigned char c = 0x01;

Does java has this data type or something similar? I have a reason
that I need to declare many hex values inside the program. I'm
thinking about migrating from C to Java. Please give me some advice.
Thank you so much.

Your terminology is a little confused. Hex (hexidecimal) is just a number radix for
expressing binary values. char and unsigned char can both be expressed in hex.

You are apparently are looking for an unsigned value, probably 8 bit. Java doesn't have
anything exactly like that. The only unsigned value is 'char', but it is 16 bits. Even
so, char is good choice, though short (signed 16 bit) or int (signed 32 bit) will do.
 
R

Roedy Green

in Java, char should be used for actual characters.

I see no reason not to use char as an unsigned short.


You must be careful reading bytes and treating them as char[] or
String since there is a translation process, but char is just a number
in Java.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top