ahmed0saber

Decimal to Binary in C#

Nov 21st, 2020
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.29 KB | None | 0 0
  1. using System;
  2. namespace DecimalToBinary
  3. {
  4. class Project1
  5. {
  6. void Main()
  7. {
  8. int x,binary=0,t=1;
  9. Console.Write("Enter a number : ");
  10. x=Convert.ToInt32(Console.ReadLine());
  11. while(x!=0){
  12.     if(x%2==1){
  13.         binary+=t;}
  14.     x/=2;
  15.     t*=10;
  16. }
  17. Console.Write("Number in binary : {0}",binary);
  18. }
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment