1 /*
2 * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
450 return x - y;
451 }
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 }
|
1 /*
2 * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
450 return x - y;
451 }
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 * Consequently, zero and positive {@code short} values are mapped
480 * to a numerically equal {@code int} value and negative {@code
481 * short} values are mapped to an {@code int} value equal to the
482 * input plus 2<sup>16</sup>.
483 *
484 * @param x the value to convert to an unsigned {@code int}
485 * @return the argument converted to {@code int} by an unsigned
486 * conversion
487 * @since 1.8
488 */
489 public static int toUnsignedInt(short x) {
490 return ((int) x) & 0xffff;
491 }
492
493 /**
494 * Converts the argument to a {@code long} by an unsigned
495 * conversion. In an unsigned conversion to a {@code long}, the
496 * high-order 48 bits of the {@code long} are zero and the
497 * low-order 16 bits are equal to the bits of the {@code short} argument.
498 *
499 * Consequently, zero and positive {@code short} values are mapped
500 * to a numerically equal {@code long} value and negative {@code
501 * short} values are mapped to a {@code long} value equal to the
502 * input plus 2<sup>16</sup>.
503 *
504 * @param x the value to convert to an unsigned {@code long}
505 * @return the argument converted to {@code long} by an unsigned
506 * conversion
507 * @since 1.8
508 */
509 public static long toUnsignedLong(short x) {
510 return ((long) x) & 0xffffL;
511 }
512
513 /** use serialVersionUID from JDK 1.1. for interoperability */
514 private static final long serialVersionUID = 7515723908773894738L;
515 }
|