Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.LinkedList;
- import java.util.Queue;
- import java.util.Stack;
- public class Program {
- static void DecToBin(int number) {
- Stack<Integer> digits = new Stack<Integer>();
- while (number != 0) {
- digits.push(number % 2);
- number /= 2;
- }
- while (digits.size() != 0) {
- System.out.print(digits.pop());
- }
- }
- static int BinToDec (int bin) {
- int dec = 0;
- int power = 0;
- while (bin != 0){
- int an = bin % 10;
- dec += an * Math.pow(2, power);
- power++;
- bin /= 10;
- }
- return dec;
- }
- public static void main(String[] args) {
- //DecToBin(200);
- System.out.println(BinToDec(11001000));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement