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

Print this page

        

@@ -438,10 +438,41 @@
     public static int compare(byte x, byte y) {
         return x - y;
     }
 
     /**
+     * Converts the argument to an {@code int} by an unsigned
+     * conversion.  In an unsigned conversion to an {@code int}, the
+     * high-order 24 bits of the {@code int} are zero and the
+     * low-order 8 bits are equal to the bits of the {@code byte} argument.
+     *
+     * @return the argument converted to {@code int} by an unsigned
+     *         conversion
+     * @param  x the value to convert to an unsigned {@code int}
+     * @since 1.7
+     */
+    public static int toUnsignedInt(byte x) {
+        return ((int) x) & 0xff;
+    }
+
+    /**
+     * Converts the argument to a {@code long} by an unsigned
+     * conversion.  In an unsigned conversion to a {@code long}, the
+     * high-order 56 bits of the {@code long} are zero and the
+     * low-order 8 bits are equal to the bits of the {@code byte} argument.
+     *
+     * @return the argument converted to {@code long} by an unsigned
+     *         conversion
+     * @param  x the value to convert to an unsigned {@code long}
+     * @since 1.7
+     */
+    public static long toUnsignedLong(byte x) {
+        return ((long) x) & 0xffL;
+    }
+
+
+    /**
      * The number of bits used to represent a {@code byte} value in two's
      * complement binary form.
      *
      * @since 1.5
      */