Java BigInteger Format formatSerialNumber(BigInteger bi)

Here you can find the source of formatSerialNumber(BigInteger bi)

Description

format Serial Number

License

EUPL

Declaration

private static String formatSerialNumber(BigInteger bi) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Digital Signature Applet//from  www  . j  av  a2  s  . c o  m
 * 
 *  Copyright (C) 2014 European Commission, Directorate-General for Justice (DG  JUSTICE), B-1049 Bruxelles/Brussel
 * 
 *  Developed by: ARHS Developments S.A. (rue Nicolas Bov? 2B, L-1253 Luxembourg)  
 * 
 *  http://www.arhs-developments.com
 * 
 *  This file is part of the "Digital Signature Applet" project.
 * 
 *  Licensed under the EUPL, version 1.1 or ? as soon they are approved by the European  Commission - subsequent versions of the EUPL (the "Licence"). 
 *  You may not use this  work except in compliance with the Licence. You may obtain a copy of the Licence at:
 * 
 *  http://ec.europa.eu/idabc/eupl.html
 * 
 *  Unless required by applicable law or agreed to in writing, software distributed under   the Licence is distributed on  
 *  an "AS IS" basis, WITHOUT WARRANTIES OR   CONDITIONS OF ANY KIND, either  express or implied. 
 * 
 *  See the Licence for the  specific language governing permissions and limitations under the Licence.
 ******************************************************************************/

import java.math.BigInteger;

public class Main {
    private static String formatSerialNumber(BigInteger bi) {
        if (bi == null) {
            return "";
        }

        String sn = bi.toString(16);
        char[] chars = sn.toUpperCase().toCharArray();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < chars.length; i++) {
            sb.append(chars[i]);
            if ((i + 1) % 2 == 0 && i < chars.length - 1) {
                sb.append(' ');
            }
        }
        return sb.toString();
    }
}

Related

  1. formatBigInteger(BigInteger bi, int length)
  2. formatBigIntegerBinary(final long value, byte[] buf, final int offset, final int length, final boolean negative)
  3. formatSerialNumber(final BigInteger serial)
  4. formatSize(BigInteger size)
  5. formatTime(BigInteger femto)