Welcome to collectivesolver - Programming & Software Q&A with Examples. A website you can trust. All programs tested and work.

Contact: aviboots(AT)netvision.net.il


Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Dental Dog Chews
FRESH BREATHIES

GlucoTrust is a brand new, science-backed supplement that supports healthy blood sugar levels AND weight loss for men and women

Everything you need to sell anywhere

Managed VPS Hosting
Affordable. Secure. Your Own Virtual Private Hosting. Faster than AWS and Rackspace

Bonsai Boy of New York Bonsai Trees and Accessories
100%

Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

24,887 questions

32,502 answers

573 users

How to convert decimal to binary in C#

2 Answers

0 votes
using System;

public class Program
{
	public static void Main(string[] args) {
		int _decimal = 23;
		int[] binary = new int[8];
		int bi = 0;

		while (_decimal > 0) {
			binary[bi++] = _decimal % 2;
			_decimal = _decimal / 2;
		}
		for (int i = binary.Length - 1; i >= 0; i--) {
			Console.Write(binary[i]);
		}
	}
}




/*
run:
  
00010111
  
*/

 




answered Jul 19 by avibootz
0 votes
using System;

public class Program
{
	public static void Main(string[] args) {
		int _decimal = 23;

		Console.WriteLine(Convert.ToString(_decimal, 2));
		
		Console.WriteLine(Convert.ToString(_decimal, 2).PadLeft(8, '0'));
	}
}




/*
run:
  
10111
00010111
  
*/

 




answered Jul 19 by avibootz
edited Jul 19 by avibootz
...