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.List;

public class Main {
    public static List<Integer> getBitsFromIntagerNumber(Integer num) {
        String binary = Integer.toBinaryString(num);
        List<Integer> list = new ArrayList<Integer>(0);
        if (num == 0)
            list.add(num);
        for (int i = 0; i < binary.length(); i++) {
            if ((int) binary.charAt(i) == 49)
                list.add((int) Math.pow(2, binary.length() - 1 - i));
        }
        return list;
    }
}