Java BigInteger to bigIntToIpV6(BigInteger argInt)

Here you can find the source of bigIntToIpV6(BigInteger argInt)

Description

big Int To Ip V

License

Open Source License

Declaration

public static String bigIntToIpV6(BigInteger argInt) 

Method Source Code


//package com.java2s;
/*/*from  w w  w  .j  a  v  a2s  .co m*/
    
Copyright (C) 2011 NTT DATA Corporation
    
This program is free software; you can redistribute it and/or
Modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, version 2.
    
This program is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the GNU General Public License for more details.
    
 */

import java.math.BigInteger;

public class Main {

    public static String bigIntToIpV6(BigInteger argInt) {

        StringBuilder str = new StringBuilder();
        for (int i = 15; i >= 0; i--) {
            int shift = 8 * i;
            Integer n = 0xff;
            BigInteger num = argInt.shiftRight(shift).and(new BigInteger(n.toString()));
            int intNum = num.intValue();
            String s = Integer.toHexString(intNum);
            if (s.length() < 2) {
                s = "0" + s;
            }
            str.append(s);
            if (i > 0 && i < 15) {
                int f = i % 2;
                str.append(f == 0 ? ":" : "");
            }
        }
        return str.toString();
    }
}

Related

  1. bigIntegerToString(final BigInteger value)
  2. bigIntegerToUnsignedByteArray(BigInteger a, int len)
  3. bigIntToArray(BigInteger data)
  4. bigIntToHash(BigInteger keyValue)
  5. bigIntToHex(BigInteger big)
  6. BigIntToPaddedByteArray(BigInteger bi, int length)
  7. bigIntToSortableBytes(BigInteger bigInt, int bigIntSize, byte[] result, int offset)
  8. biToHex(BigInteger bi)
  9. byteConvert32Bytes(BigInteger n)