Java Unsigned Number Create unsignedToSigned(int[] ints)

Here you can find the source of unsignedToSigned(int[] ints)

Description

Convert an unsigned set of bytes to a signed set.

License

Open Source License

Parameter

Parameter Description
ints an array of signed bytes

Return

an array of unsigned bytes

Declaration

public static byte[] unsignedToSigned(int[] ints) 

Method Source Code

//package com.java2s;
/*/*from  w w w.j av a2 s .  c om*/
 * $Id$
 * 
 * Copyright (c) 2008-2014 David Muller <roxon@users.sourceforge.net>.
 * All rights reserved. Use of the code is allowed under the
 * Artistic License 2.0 terms, as specified in the LICENSE file
 * distributed with this code, or available from
 * http://www.opensource.org/licenses/artistic-license-2.0.php
 */

public class Main {
    /**
     * Convert an unsigned set of bytes to a signed set.
     * 
     * @param ints an array of signed bytes
     * @return an array of unsigned bytes
     */
    public static byte[] unsignedToSigned(int[] ints) {
        final byte[] result = new byte[ints.length];
        for (int i = 0; i < ints.length; i++) {
            result[i] = (byte) (ints[i] & 0xFF);
        }
        return result;
    }
}

Related

  1. unsignedShortToInt(final byte[] b)
  2. unsignedShortToInt(short n)
  3. unsignedSubOverflow(int operand1, int operand2)
  4. unsignedToBytes(byte b)
  5. unsignedToSigned(int unsigned, int size)
  6. unsignedToSigned(int[] unsignedBytes)
  7. unsignedToSigned(long value, int size)
  8. unsignedToSigned16(char value)
  9. unsignedToSigned8(char value)