Does java has data type for hex value?

Discussion in 'Java' started by Abby, Aug 14, 2003.

  1. Abby

    Abby Guest

    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.
    Abby, Aug 14, 2003
    #1
    1. Advertising

  2. 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
    --
    Please reply in the newsgroup, not by email!
    Java programming tips: http://jiu.sourceforge.net/javatips.html
    Other Java pages: http://www.geocities.com/marcoschmidt.geo/java.html
    Marco Schmidt, Aug 14, 2003
    #2
    1. Advertising

  3. Abby wrote:
    >
    > 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.

    --
    Lee Fesperman, FirstSQL, Inc. (http://www.firstsql.com)
    ==============================================================
    * The Ultimate DBMS is here!
    * FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
    Lee Fesperman, Aug 14, 2003
    #3
  4. Abby

    Roedy Green Guest

    On Sat, 16 Aug 2003 00:38:02 -0700, "Jon A. Cruz" <>
    wrote or quoted :

    >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.
    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, Aug 16, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    10
    Views:
    6,192
    Neredbojias
    Aug 19, 2005
  2. Bengt Richter
    Replies:
    6
    Views:
    467
    Juha Autero
    Aug 19, 2003
  3. jack
    Replies:
    4
    Views:
    586
  4. tim

    hex string to hex value

    tim, Nov 22, 2005, in forum: Python
    Replies:
    8
    Views:
    18,853
  5. tim
    Replies:
    2
    Views:
    1,561
    Dennis Lee Bieber
    Nov 23, 2005
Loading...

Share This Page