Java tutorial
//package com.java2s; /* * Copyright (C) 2010 Gassan Idriss * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { protected static String transformSerial(CharSequence n, int srcBase, int dstBase, int p1Width, int p1Padding, int p2Padding) { String p1 = lPad(Long.toString(Long.parseLong(n.toString().substring(0, p1Width), srcBase), dstBase), p1Padding, "0"); String p2 = lPad(Long.toString(Long.parseLong(n.toString().substring(p1Width), srcBase), dstBase), p2Padding, "0"); String c = p1 + p2; return c.toUpperCase(); } protected static String lPad(String s, int len, String p) { if (s.length() >= len) { return s; } return lPad(p + s, len, p); } }