src/share/classes/java/lang/Byte.java

Print this page




 423 
 424     /**
 425      * Compares two {@code byte} values numerically.
 426      * The value returned is identical to what would be returned by:
 427      * <pre>
 428      *    Byte.valueOf(x).compareTo(Byte.valueOf(y))
 429      * </pre>
 430      *
 431      * @param  x the first {@code byte} to compare
 432      * @param  y the second {@code byte} to compare
 433      * @return the value {@code 0} if {@code x == y};
 434      *         a value less than {@code 0} if {@code x < y}; and
 435      *         a value greater than {@code 0} if {@code x > y}
 436      * @since 1.7
 437      */
 438     public static int compare(byte x, byte y) {
 439         return x - y;
 440     }
 441 
 442     /**































 443      * The number of bits used to represent a {@code byte} value in two's
 444      * complement binary form.
 445      *
 446      * @since 1.5
 447      */
 448     public static final int SIZE = 8;
 449 
 450     /** use serialVersionUID from JDK 1.1. for interoperability */
 451     private static final long serialVersionUID = -7183698231559129828L;
 452 }


 423 
 424     /**
 425      * Compares two {@code byte} values numerically.
 426      * The value returned is identical to what would be returned by:
 427      * <pre>
 428      *    Byte.valueOf(x).compareTo(Byte.valueOf(y))
 429      * </pre>
 430      *
 431      * @param  x the first {@code byte} to compare
 432      * @param  y the second {@code byte} to compare
 433      * @return the value {@code 0} if {@code x == y};
 434      *         a value less than {@code 0} if {@code x < y}; and
 435      *         a value greater than {@code 0} if {@code x > y}
 436      * @since 1.7
 437      */
 438     public static int compare(byte x, byte y) {
 439         return x - y;
 440     }
 441 
 442     /**
 443      * Converts the argument to an {@code int} by an unsigned
 444      * conversion.  In an unsigned conversion to an {@code int}, the
 445      * high-order 24 bits of the {@code int} are zero and the
 446      * low-order 8 bits are equal to the bits of the {@code byte} argument.
 447      *
 448      * @return the argument converted to {@code int} by an unsigned
 449      *         conversion
 450      * @param  x the value to convert to an unsigned {@code int}
 451      * @since 1.7
 452      */
 453     public static int toUnsignedInt(byte x) {
 454         return ((int) x) & 0xff;
 455     }
 456 
 457     /**
 458      * Converts the argument to a {@code long} by an unsigned
 459      * conversion.  In an unsigned conversion to a {@code long}, the
 460      * high-order 56 bits of the {@code long} are zero and the
 461      * low-order 8 bits are equal to the bits of the {@code byte} argument.
 462      *
 463      * @return the argument converted to {@code long} by an unsigned
 464      *         conversion
 465      * @param  x the value to convert to an unsigned {@code long}
 466      * @since 1.7
 467      */
 468     public static long toUnsignedLong(byte x) {
 469         return ((long) x) & 0xffL;
 470     }
 471 
 472 
 473     /**
 474      * The number of bits used to represent a {@code byte} value in two's
 475      * complement binary form.
 476      *
 477      * @since 1.5
 478      */
 479     public static final int SIZE = 8;
 480 
 481     /** use serialVersionUID from JDK 1.1. for interoperability */
 482     private static final long serialVersionUID = -7183698231559129828L;
 483 }