Java Unsigned Int Create toUnsignedInt(char[] bytes, boolean le)

Here you can find the source of toUnsignedInt(char[] bytes, boolean le)

Description

to Unsigned Int

License

Open Source License

Declaration

public static long toUnsignedInt(char[] bytes, boolean le) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2000, 2014 QNX Software Systems and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://  w ww  .  j  a  v  a 2  s.  c  o  m
 *     QNX Software Systems - Initial API and implementation
 *     Freescale Semiconductor - Address watchpoints, https://bugs.eclipse.org/bugs/show_bug.cgi?id=118299
 *     Patrick Chuong (Texas Instruments) -   Update CDT ToggleBreakpointTargetFactory enablement (340177)
 *     Marc Khouzam (Ericsson) - Support for dynamic printf (400628)
 *******************************************************************************/

public class Main {
    public static long toUnsignedInt(char[] bytes, boolean le) {
        if (bytes.length != 8)
            return 0;
        return Long.parseLong(bytesToString(bytes, le, false), 16);
    }

    private static String bytesToString(char[] bytes, boolean le,
            boolean signed) {
        char[] copy = new char[bytes.length];
        if (le) {
            for (int i = 0; i < bytes.length / 2; ++i) {
                copy[2 * i] = bytes[bytes.length - 2 * i - 2];
                copy[2 * i + 1] = bytes[bytes.length - 2 * i - 1];
            }
        } else {
            System.arraycopy(bytes, 0, copy, 0, copy.length);
        }
        return new String(copy);
    }
}

Related

  1. toUnsignedInt(byte b)
  2. toUnsignedInt(byte b1, byte b2, byte b3, byte b4)
  3. toUnsignedInt(byte value)
  4. toUnsignedInt(byte x)
  5. toUnsignedInt(byte[] a)
  6. toUnsignedInt(int i)
  7. toUnsignedInt(int value)
  8. toUnsignedInt(int value)
  9. toUnsignedInt(long value)