Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static byte[] int2bcd(int number) {
        byte[] bcdByte = new byte[10];
        int i = 0;
        for (; number > 0; ++i) {
            bcdByte[i] = (byte) (number % 10);
            number /= 10;

            if (number > 0) {
                bcdByte[i] |= (byte) ((number % 10) << 4);
                number /= 10;
            }
        }
        byte[] bcdRet = new byte[i > 1 ? i : 1];
        System.arraycopy(bcdByte, 0, bcdRet, 0, i);
        return bcdRet;
    }
}