N
N
Nikolay2015-10-01 16:53:25
Algorithms
Nikolay, 2015-10-01 16:53:25

Converting from decimal to binary and back in C#?

How to quickly convert from decimal to binary in C#?
And how to add zeros when converting from binary to decimal:

int i = Convert.ToInt32("2");
            Console.WriteLine(Convert.ToString(i, 2));

The output is 10, but it is necessary - 0010 how to format the output?
And how to divide into two parts 1101 0101?
A = 1101
B = 0101

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Taran, 2015-10-01
@xkeirainx

Read about string formatting on the official site , and choose the implementation that suits you best.

N
Nikolay, 2015-10-01
@zzzmaikzzz

Found the answer myself much easier Convert.ToString(To[i], 2).PadLeft(8, '0');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question