Problem 22

4 comments on “Problem 22”


  • swapnil

    decNum=int(input())
    rem=0
    res=[]
    originalNum=decNum
    while decNum>0:
    rem=decNum%2
    decNum=decNum//2
    res.append(rem)
    print(”.join(str(i) for i in res[len(res)-1::-1]))


  • The Bong

    import java.util.Stack;

    public class DecimelToBinary {
    public static void main(String[] args) {
    System.out.println(decToBinary(50));
    }
    static String decToBinary(int num) {
    Stack stack = new Stack();
    String resString = “”;
    int temp = num;
    while (temp >= 1) {
    String remainder = String.valueOf(temp % 2);
    stack.push(remainder);
    temp /= 2;
    }
    while (!stack.isEmpty()) {
    resString += stack.peek();
    stack.pop();
    }
    return resString;
    }
    }