Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Decimal_to_Binary
- {
- class Program
- {
- static void Main(string[] args)
- {
- var n = 1024;
- DecimalToBinary(8);
- }
- static void DecimalToBinary(int n)
- {
- int[] array = new int[(int)Math.Log(n, 2) + 1];
- var idx = array.Length - 1; // no reverse needed ;)
- while (n > 0)
- {
- var rem = n % 2;
- array[idx] = rem;
- n /= 2;
- idx--;
- }
- //Array.Reverse(array);
- for (int i = 0; i < array.Length; i++)
- {
- Console.Write(array[i]);
- }
- Console.ReadLine();
- }
- }
- }
- https://www.youtube.com/watch?v=4vNlt_EDw1Q
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement