byte to decimal, byte to hex, byte to char

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oll3i
    Contributor
    • Mar 2007
    • 679

    #1

    byte to decimal, byte to hex, byte to char

    i need to convert byte to a decimal , hex and char
    how do i do that?

    thank You
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by oll3i
    i need to convert byte to a decimal , hex and char
    how do i do that?

    thank You
    Conversion to a char is merely a cast:

    Code:
    byte b= ...
    char c= (char)(b&0xff);
    The others are just String representations of a byte which is just a small int value; check the API documentation of the Integer class:

    Code:
    byte b= ...;
    int i= b&0xff;
    // get a String representation of int i here ..
    Note that the code snippets above assume an unsigned byte value, i,e. the sign extension bits are masked away.

    kind regards,

    Jos

    Comment

    Working...