Java Unsigned Number Create unsignedIntToString(int x, int radix)

Here you can find the source of unsignedIntToString(int x, int radix)

Description

Returns a string representation of x for the given radix, where x is treated as unsigned.

License

Apache License

Parameter

Parameter Description
x the value to convert to a string.
radix the radix to use while working with x

Exception

Parameter Description
IllegalArgumentException if radix is not between Character#MIN_RADIX and Character#MAX_RADIX.

Declaration

private static String unsignedIntToString(int x, int radix) 

Method Source Code

//package com.java2s;
//Licensed under the Apache License, Version 2.0 (the "License");

public class Main {
    static final long INT_MASK = 0xffffffffL;

    /**/*  w  w w.j av a 2 s .c o  m*/
     * Returns a string representation of x, where x is treated as unsigned.
     */
    public static String unsignedIntToString(int x) {
        return unsignedIntToString(x, 10);
    }

    /**
     * Returns a string representation of {@code x} for the given radix, where {@code x} is treated as unsigned.
     *
     * @param x
     *            the value to convert to a string.
     * @param radix
     *            the radix to use while working with {@code x}
     * @throws IllegalArgumentException
     *             if {@code radix} is not between {@link Character#MIN_RADIX} and {@link Character#MAX_RADIX}.
     */
    private static String unsignedIntToString(int x, int radix) {
        long asLong = x & INT_MASK;
        return Long.toString(asLong, radix);
    }
}

Related

  1. unsignedIntToLong(byte[] source)
  2. unsignedIntToLong(int value)
  3. unsignedIntToLong(Integer i)
  4. unsignedIntToSignedByte(final int i)
  5. unsignedIntToString(int x)
  6. unsignedIntValue(byte[] data, int offset)
  7. unsignedLeb128Size(int value)
  8. unsignedLessThan(long a, long b)
  9. unsignedLocalIntersect2by2(final short[] set1, final int length1, final short[] set2, final int length2, final short[] buffer)