Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class MainClass {
- public static void Main (string[] args) {
- int num = Convert.ToInt32(Console.ReadLine());
- int arrayLength = (int) Math.Log(num,2) + 1; // symbols in number in binary format
- int[] array = new int[arrayLength]; //array to hold number in binary format
- int counter = 0;
- while(num > 0)
- {
- array[counter++] = num % 2;
- num = num / 2;
- }
- long binaryNum = 0; //variable to hold number in binary format
- for(int i = arrayLength-1 ; i >=0; --i)
- binaryNum = binaryNum*10 + array[i];
- Console.WriteLine(binaryNum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement