< prev index next >

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

Print this page
rev 12859 : 8033148: Lexicographic comparators for arrays
Reviewed-by: jrose, chegar, bchristi, mduigou
rev 12351 : 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
Summary: Annotate possibly intrinsified methods with @HotSpotIntrinsicCandidate. Add checks omitted by intrinsics to the library code. Add CheckIntrinsics flags to check consistency of intrinsics.
Reviewed-by: jrose, kvn, thartmann, vlivanov, abuckley, darcy, ascarpino, briangoetz, alanb, aph, dnsimon
rev 10469 : 8054834: Modular Source Code
Reviewed-by: alanb, chegar, ihse, mduigou
Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com


 446 
 447     /**
 448      * Compares two {@code byte} values numerically.
 449      * The value returned is identical to what would be returned by:
 450      * <pre>
 451      *    Byte.valueOf(x).compareTo(Byte.valueOf(y))
 452      * </pre>
 453      *
 454      * @param  x the first {@code byte} to compare
 455      * @param  y the second {@code byte} to compare
 456      * @return the value {@code 0} if {@code x == y};
 457      *         a value less than {@code 0} if {@code x < y}; and
 458      *         a value greater than {@code 0} if {@code x > y}
 459      * @since 1.7
 460      */
 461     public static int compare(byte x, byte y) {
 462         return x - y;
 463     }
 464 
 465     /**
















 466      * Converts the argument to an {@code int} by an unsigned
 467      * conversion.  In an unsigned conversion to an {@code int}, the
 468      * high-order 24 bits of the {@code int} are zero and the
 469      * low-order 8 bits are equal to the bits of the {@code byte} argument.
 470      *
 471      * Consequently, zero and positive {@code byte} values are mapped
 472      * to a numerically equal {@code int} value and negative {@code
 473      * byte} values are mapped to an {@code int} value equal to the
 474      * input plus 2<sup>8</sup>.
 475      *
 476      * @param  x the value to convert to an unsigned {@code int}
 477      * @return the argument converted to {@code int} by an unsigned
 478      *         conversion
 479      * @since 1.8
 480      */
 481     public static int toUnsignedInt(byte x) {
 482         return ((int) x) & 0xff;
 483     }
 484 
 485     /**




 446 
 447     /**
 448      * Compares two {@code byte} values numerically.
 449      * The value returned is identical to what would be returned by:
 450      * <pre>
 451      *    Byte.valueOf(x).compareTo(Byte.valueOf(y))
 452      * </pre>
 453      *
 454      * @param  x the first {@code byte} to compare
 455      * @param  y the second {@code byte} to compare
 456      * @return the value {@code 0} if {@code x == y};
 457      *         a value less than {@code 0} if {@code x < y}; and
 458      *         a value greater than {@code 0} if {@code x > y}
 459      * @since 1.7
 460      */
 461     public static int compare(byte x, byte y) {
 462         return x - y;
 463     }
 464 
 465     /**
 466      * Compares two {@code byte} values numerically treating the values
 467      * as unsigned.
 468      *
 469      * @param  x the first {@code byte} to compare
 470      * @param  y the second {@code byte} to compare
 471      * @return the value {@code 0} if {@code x == y}; a value less
 472      *         than {@code 0} if {@code x < y} as unsigned values; and
 473      *         a value greater than {@code 0} if {@code x > y} as
 474      *         unsigned values
 475      * @since 9
 476      */
 477     public static int compareUnsigned(byte x, byte y) {
 478         return Byte.toUnsignedInt(x) - Byte.toUnsignedInt(y);
 479     }
 480 
 481     /**
 482      * Converts the argument to an {@code int} by an unsigned
 483      * conversion.  In an unsigned conversion to an {@code int}, the
 484      * high-order 24 bits of the {@code int} are zero and the
 485      * low-order 8 bits are equal to the bits of the {@code byte} argument.
 486      *
 487      * Consequently, zero and positive {@code byte} values are mapped
 488      * to a numerically equal {@code int} value and negative {@code
 489      * byte} values are mapped to an {@code int} value equal to the
 490      * input plus 2<sup>8</sup>.
 491      *
 492      * @param  x the value to convert to an unsigned {@code int}
 493      * @return the argument converted to {@code int} by an unsigned
 494      *         conversion
 495      * @since 1.8
 496      */
 497     public static int toUnsignedInt(byte x) {
 498         return ((int) x) & 0xff;
 499     }
 500 
 501     /**


< prev index next >