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