Java Integer to Bit intToBits(int n, int size)

Here you can find the source of intToBits(int n, int size)

Description

int To Bits

License

Open Source License

Declaration

public static int[] intToBits(int n, int size) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static int[] intToBits(int n, int size) {
        int[] bits = new int[size];
        for (int i = 0; i < size; i++) {
            bits[i] = (n / (int) Math.pow(2, i)) % 2;
        }/*  ww  w. j a v a 2 s.  c  o  m*/
        return bits;
    }
}

Related

  1. convertIntToBits(int num)
  2. convertIntToBitsWithPadding(int num)
  3. intToBits(int in, int min, int max, int numBits)
  4. intToBits(int no)
  5. intToBits(int pInt, boolean[] pBits)