Advertisement
Guest User

Untitled

a guest
Feb 20th, 2016
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. From Decimal to Binary:
  2. int n = int.Parse(Console.ReadLine());
  3. var convert = Convert.ToString(n, 2);
  4. Console.WriteLine(convert);
  5.  
  6. From Binary to Decimal:
  7. string bin = Console.ReadLine();
  8. int result = Convert.ToInt32 (bin, 2 );
  9. Console.WriteLine(result);
  10.  
  11. From Decimal To Hexadecimal:
  12. int n = int.Parse(Console.ReadLine());
  13. var convert = Convert.ToString(n, 16);
  14. Console.WriteLine(convert);
  15. 2nd Version with placeholder:
  16. int n = int.Parse(Console.ReadLine());
  17. Console.WriteLine("{0:X}" , n);
  18.  
  19. From Hexadecimal to Decimal:
  20. string bin = Console.ReadLine();
  21. int result = Convert.ToInt32(bin, 16);
  22. Console.WriteLine(result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement