Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //Using loops write a program that converts an integer number to its binary representation. The input is entered as long.
- //The output should be a variable of type string. Do not use the built-in .NET functionality.
- // decimal binary
- // 0 0
- // 3 11
- // 43691 1010101010101011
- // 236476736 1110000110000101100101000000
- class DecimalToBinaryNumber
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- string nbinary = null;
- int r = 0;
- while (n > 0)
- {
- r = n % 2;
- n /= 2;
- nbinary += r;
- }
- Console.WriteLine(nbinary);
- string nBinary2 = null;
- for (int i = nbinary.Length - 1; i >= 0; i--)
- {
- nBinary2 += nbinary[i];
- }
- Console.WriteLine(nBinary2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement