+ 3

Code for convert demical to binary?

code

30th Sep 2017, 11:41 AM
Emy
Emy - avatar
6 Antworten
+ 9
using System; namespace Decimal_to_Binary_Converter { class MainClass { static void Main(string[] args) { string num = ""; Console.WriteLine("Enter the decimal number: "); int x = int.Parse(Console.ReadLine()); while(x != 0) { num = x % 2 + num; x /= 2; } Console.WriteLine(num); } } }
30th Sep 2017, 11:54 AM
Vukan
Vukan - avatar
+ 2
good work , perfect my friends
30th Sep 2017, 12:57 PM
Emy
Emy - avatar
+ 2
import java.util.Scanner; public class DemicalToBinary2 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner s = new Scanner(System.in); System.out.println("Enter the Number = "); int n = s.nextInt(); test2 t2 = new test2(); t2.DTB(n); //System.out.println(Integer.toBinaryString(n)); } } class test2 { void DTB(int Number) { int[] binary = new int[25]; int index = 0; while (Number > 0) { binary[index++] = Number % 2; Number = Number / 2; } for (int i = index - 1; i >= 0; i--) { System.out.print(binary[i]); } } }
30th Sep 2017, 1:18 PM
Emy
Emy - avatar