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

Print this page




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































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


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