Java Unsigned Number Create unsignedIntToString(int x)

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

Description

Returns a string representation of x, where x is treated as unsigned.

License

Apache License

Declaration

public static String unsignedIntToString(int x) 

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;

    /**//from  w  w  w .j  a  v  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[] bytes)
  2. unsignedIntToLong(byte[] source)
  3. unsignedIntToLong(int value)
  4. unsignedIntToLong(Integer i)
  5. unsignedIntToSignedByte(final int i)
  6. unsignedIntToString(int x, int radix)
  7. unsignedIntValue(byte[] data, int offset)
  8. unsignedLeb128Size(int value)
  9. unsignedLessThan(long a, long b)