Max Max - 4 days ago 4
C# Question

easy and fast way to convert an int to binary?

What I am looking for is something like PHPs

decbin
function in C#. That function converts decimals to its representation as a string.

For example, when using
decbin(21)
it returns
10101
as result.

I found this function which basically does what I want, but maybe there is a better / faster way?

Answer
var result = Convert.ToString(number, 2);

– Almost the only use for the (otherwise useless) Convert class.

Comments