Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.ArrayList;
import java.util.Collections;

import java.util.SortedSet;
import java.util.TreeSet;

public class Main {
    /**
     * Get the sorted selected positions in a byte with the right most
     * position as zero.
     * @param input Byte to be evaluated
     * @return Array of integer positions.
     */
    public static SortedSet<Integer> getSelectedPCR(byte input) {
        ArrayList<Integer> arrayList = new ArrayList<Integer>();
        byte mask = 0x01;
        for (int i = 0; i <= 7; i++) {
            int value = (input >>> i) & mask;
            if (value == 1) {
                arrayList.add(i);
            }
        }
        Collections.sort(arrayList);
        return Collections.unmodifiableSortedSet(new TreeSet<Integer>(arrayList));
    }
}