+ 3
Code for convert demical to binary?
code
3 Respostas
+ 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);
}
}
}
+ 2
good work , perfect my friends
+ 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]);
}
}
}