Convert.ToString() to binary format not working as expected

前端 未结 7 807
说谎
说谎 2021-01-17 10:33
int i = 20;
string output = Convert.ToString(i, 2); // Base2 formatting
i = -20;
output = Convert.ToString(i, 2);
Value   Expected                       


        
7条回答
  •  遥遥无期
    2021-01-17 11:08

    If you would get rid of this "effect" - use Math.Abs() method to get number value without sign,

    string output = Convert.ToString(Math.Abs(i), 2); // Base2 
    

提交回复
热议问题