Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > 8-bit unsigned integers in Java

Reply
Thread Tools

8-bit unsigned integers in Java

 
 
jeff
Guest
Posts: n/a
 
      03-07-2004
hi, i'm porting a toy crypto algorithm to java. the original cipher was
written in C and used unsigned char's for 8-bit bytes with the range 0..255.
i need a similar datatype in java, but the primitive 'byte' is signed
(range -128..+127). does anyone have any suggestions for a 8-bit
unsigned datatype in java?

thanks in advance

 
Reply With Quote
 
 
 
 
Mike Schilling
Guest
Posts: n/a
 
      03-07-2004

"jeff" <(E-Mail Removed)> wrote in message
news:c2fj6j$1sq6bd$(E-Mail Removed)-berlin.de...
> hi, i'm porting a toy crypto algorithm to java. the original cipher was
> written in C and used unsigned char's for 8-bit bytes with the range

0..255.
> i need a similar datatype in java, but the primitive 'byte' is signed
> (range -128..+127). does anyone have any suggestions for a 8-bit
> unsigned datatype in java?


Use shorts and mask to 8 bits where necessary.


 
Reply With Quote
 
 
 
 
Mark Thornton
Guest
Posts: n/a
 
      03-07-2004
jeff wrote:
> hi, i'm porting a toy crypto algorithm to java. the original cipher was
> written in C and used unsigned char's for 8-bit bytes with the range
> 0..255.
> i need a similar datatype in java, but the primitive 'byte' is signed
> (range -128..+127). does anyone have any suggestions for a 8-bit
> unsigned datatype in java?
>
> thanks in advance
>


There are several choices. One is to use byte as it is (signed) but not
that many operations produce the same result (bit pattern) for both
signed and unsigned values it is merely a matter of interpretation. For
those operations where the sign actually matters you will have to rework
the equations.
Another possibility is to use the char type for the calculations. This
is unsigned albeit with 16 bits instead of 8 ... just ignore the content
of the upper 8 bits.

Mark Thornton

 
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
(int) -> (unsigned) -> (int) or (unsigned) -> (int) -> (unsigned):I'll loose something? pozz C Programming 12 03-20-2011 11:32 PM
Trap representations for unsigned integers Army1987 C Programming 17 04-29-2007 11:47 PM
casting unsigned integers techie C++ 4 10-13-2006 06:01 PM
comparing signed and unsigned integers Joe Van Dyk C Programming 3 06-25-2006 09:11 PM
Adding and multiplying two unsigned integers Edith Gross C++ 5 05-01-2005 04:48 PM



Advertisments