Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//PduUtils is distributed under the terms of the Apache License version 2.0

import java.util.*;

public class Main {
    public static byte[] unencodedSeptetsToEncodedSeptets(byte[] septetBytes) {
        byte[] txtBytes;
        byte[] txtSeptets;
        int txtBytesLen;
        BitSet bits;
        int i, j;
        txtBytes = septetBytes;
        txtBytesLen = txtBytes.length;
        bits = new BitSet();
        for (i = 0; i < txtBytesLen; i++)
            for (j = 0; j < 7; j++)
                if ((txtBytes[i] & (1 << j)) != 0)
                    bits.set((i * 7) + j);
        // big diff here
        int encodedSeptetByteArrayLength = txtBytesLen * 7 / 8 + ((txtBytesLen * 7 % 8 != 0) ? 1 : 0);
        txtSeptets = new byte[encodedSeptetByteArrayLength];
        for (i = 0; i < encodedSeptetByteArrayLength; i++) {
            for (j = 0; j < 8; j++) {
                txtSeptets[i] |= (byte) ((bits.get((i * 8) + j) ? 1 : 0) << j);
            }
        }
        return txtSeptets;
    }
}