ellapt

T10.8.BinOfShort

Jan 22nd, 2013
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. using System;
  2.  
  3. class BinOfShort
  4. {
  5. static void BinRepresOfShort(short start, short end)
  6. {
  7. short decNumber = 0;
  8.  
  9. for (short n = start; n <= end; n++)
  10. {
  11. decNumber = n;
  12. Console.Write("");
  13. string binaryStr = "";
  14. for (int i = 0; i < 16; i++)
  15. {
  16. int temp = decNumber&1;
  17. binaryStr = temp+binaryStr;
  18. decNumber>>=1;
  19. }
  20. Console.WriteLine("{0}\t{1,10}", n, binaryStr);
  21. }
  22. }
  23.  
  24. static void Main()
  25. {
  26. Console.WriteLine("Binary representation of 16-bit signed integers from -10 to 10: \n");
  27.  
  28. BinRepresOfShort(-10, 10);
  29.  
  30. // BinRepresOfShort(short.MinValue, short.MinValue + 25);
  31.  
  32. // BinRepresOfShort(32745, 32766);
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment