src/share/classes/java/lang/Short.java

Print this page




 446 
 447     /**
 448      * The number of bits used to represent a {@code short} value in two's
 449      * complement binary form.
 450      * @since 1.5
 451      */
 452     public static final int SIZE = 16;
 453 
 454     /**
 455      * Returns the value obtained by reversing the order of the bytes in the
 456      * two's complement representation of the specified {@code short} value.
 457      *
 458      * @return the value obtained by reversing (or, equivalently, swapping)
 459      *     the bytes in the specified {@code short} value.
 460      * @since 1.5
 461      */
 462     public static short reverseBytes(short i) {
 463         return (short) (((i & 0xFF00) >> 8) | (i << 8));
 464     }
 465 































 466     /** use serialVersionUID from JDK 1.1. for interoperability */
 467     private static final long serialVersionUID = 7515723908773894738L;
 468 }


 446 
 447     /**
 448      * The number of bits used to represent a {@code short} value in two's
 449      * complement binary form.
 450      * @since 1.5
 451      */
 452     public static final int SIZE = 16;
 453 
 454     /**
 455      * Returns the value obtained by reversing the order of the bytes in the
 456      * two's complement representation of the specified {@code short} value.
 457      *
 458      * @return the value obtained by reversing (or, equivalently, swapping)
 459      *     the bytes in the specified {@code short} value.
 460      * @since 1.5
 461      */
 462     public static short reverseBytes(short i) {
 463         return (short) (((i & 0xFF00) >> 8) | (i << 8));
 464     }
 465 
 466 
 467     /**
 468      * Converts the argument to an {@code int} by an unsigned
 469      * conversion.  In an unsigned conversion to an {@code int}, the
 470      * high-order 16 bits of the {@code int} are zero and the
 471      * low-order 16 bits are equal to the bits of the {@code short} argument.
 472      *
 473      * @return the argument converted to {@code int} by an unsigned
 474      *         conversion
 475      * @param  x the value to convert to an unsigned {@code int}
 476      * @since 1.7
 477      */
 478     public static int toUnsignedInt(short x) {
 479         return ((int) x) & 0xffff;
 480     }
 481 
 482     /**
 483      * Converts the argument to a {@code long} by an unsigned
 484      * conversion.  In an unsigned conversion to a {@code long}, the
 485      * high-order 48 bits of the {@code long} are zero and the
 486      * low-order 16 bits are equal to the bits of the {@code short} argument.
 487      *
 488      * @return the argument converted to {@code long} by an unsigned
 489      *         conversion
 490      * @param  x the value to convert to an unsigned {@code long}
 491      * @since 1.7
 492      */
 493     public static long toUnsignedLong(short x) {
 494         return ((long) x) & 0xffffL;
 495     }
 496 
 497     /** use serialVersionUID from JDK 1.1. for interoperability */
 498     private static final long serialVersionUID = 7515723908773894738L;
 499 }