Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Does java has data type for hex value?

Reply
Thread Tools

Does java has data type for hex value?

 
 
Abby
Guest
Posts: n/a
 
      08-14-2003
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.
 
Reply With Quote
 
 
 
 
Marco Schmidt
Guest
Posts: n/a
 
      08-14-2003
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
 
Reply With Quote
 
 
 
 
Lee Fesperman
Guest
Posts: n/a
 
      08-14-2003
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)
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      08-16-2003
On Sat, 16 Aug 2003 00:38:02 -0700, "Jon A. Cruz" <(E-Mail Removed)>
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hex string to hex value tim Python 8 11-23-2005 06:27 PM
[Fwd: Re: hex string to hex value] tim Python 2 11-23-2005 07:18 AM
Hex Color Codes - Hex 6 <=> Hex 3 lucanos@gmail.com HTML 10 08-18-2005 11:21 PM
hex value in string back to real hex value jack Python 4 09-08-2004 07:11 AM
hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ?? Bengt Richter Python 6 08-19-2003 07:33 AM



Advertisments