Java Stack Usage getBinary(long input)

Here you can find the source of getBinary(long input)

Description

get Binary

License

Open Source License

Declaration

public static Stack<Integer> getBinary(long input) 

Method Source Code

//package com.java2s;
/**/*  ww w .ja v  a2  s.  com*/
 * OpenCPS is the open source Core Public Services software
 * Copyright (C) 2016-present OpenCPS community
    
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
    
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>
 */

import java.util.Stack;

public class Main {
    public static Stack<Integer> getBinary(long input) {
        Stack<Integer> binaryStack = new Stack<Integer>();
        while (input != 0) {
            binaryStack.push((int) input % 2);
            input = input / 2;
        }
        return binaryStack;
    }
}

Related

  1. endsWithIgnoreWhiteSpace(String decl, String token)
  2. getOperands(Stack stack, int nOperands)
  3. getPermutationsRec(List permutations, byte[] order, List> remaining, int index)
  4. getPostOrder(List inOrderList)
  5. getRelativePath(Stack pathStack)