Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. static string ZwrocBinarnie2(int liczba)
  2.         {
  3.             if (liczba >= 0)
  4.             {
  5.                 string output = "";
  6.                 if (liczba == 0)
  7.                 {
  8.                     return "0";
  9.                 }
  10.                 while (liczba != 0)
  11.                 {
  12.                     output = Convert.ToString(liczba & 1) + output;
  13.                     liczba >>= 1;
  14.                 }
  15.                 return output;
  16.             }
  17.             else
  18.             {
  19.                 string output = "";
  20.                 liczba = liczba * (-1);
  21.                 liczba = ~liczba;
  22.                 liczba++;
  23.                 while (liczba != -1)
  24.                 {
  25.                     output = Convert.ToString(liczba & 1) + output;
  26.                     liczba >>= 1;
  27.                 }
  28.                 for (int i = output.Length; i < 32; i++)
  29.                 {
  30.                     output = "1" + output;
  31.                 }
  32.                 return output;
  33.             }
  34.  
  35.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement