answersLogoWhite

0

Here's a simple Java method to perform the conversion from decimal to a binary string representation:
public String toBinaryString(int n) {
StringBuilder sb = new StringBuilder();
while(n != 0) {
sb.insert(0, n % 2 != 0 ? '1' : '0');
n /= 2;
}
return sb.toString();
}

The java.lang.Integer class provides a conversion helper method between decimal (integer) and binary numbers in string form called toBinaryString().

String binaryValue = Integer.toBinaryString(43) // 43-> "101011"

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

How do you write a c program to convert binary to decimal by using while statement?

write a c++ program to convert binary number to decimal number by using while statement


Write a c program to convert binary number to decimal number?

How is this a question? Sounds like you should do more of your homework offline.


Write algorithms and draw a corresponding flow chart to convert a decimal number to binary equiavalent?

Write algorithms and draw a corresponding flow chart to convert a decimal number to binary equivalent?


How do you write program decimal to binary in verilog?

To convert a decimal number to binary in Verilog, you can use the built-in reg or wire types to store the binary value. First, define a module and declare an input for the decimal number. You can then use an assignment statement to convert the decimal to binary by assigning the input directly to the output, as Verilog implicitly handles the conversion. For example: module decimal_to_binary(input [7:0] decimal, output reg [7:0] binary); always @(*) begin binary = decimal; // Implicit conversion from decimal to binary end endmodule This code will take an 8-bit decimal input and output its binary representation.


How do you convert Binary-to-Decimal and Decimal-to-Binary?

You can use a table to convert binary to decimal & back:MSBBinary DigitLSB2827262524232221202561286432168421Figure out the greatest power that will fit into the number you want to convert to binary. Move to the next lower power of two. If you can fit into the next lower number write down a "1", if it can't put down "0". Put together the binary answer.


Can you explain the process of converting numbers from decimal to binary?

To convert a decimal number to binary, you divide the decimal number by 2 and write down the remainder. Then, divide the quotient by 2 and write down the remainder again. Repeat this process until the quotient is 0. The binary number is the remainders read in reverse order.


How do you write 18 as binary?

Decimal 18 is 10010 in binary


How do you write 23 binary?

Decimal 23 is 10111 in binary


How do you write 26 in binary?

Decimal 26 is 11010 in binary


How do you write 27 binary?

Decimal 27 is 11011 in binary


What decimal number is equal to the decimal no 7 How do you reach the conclusion of 0111?

When you write the decimal number '7' in Base-2 (binary), you write '0111'.


How do you you write know in binary code?

k n o w ? First convert it to ASCII code ... 107 110 111 119 (all decimal numbers) Then convert to binary : 1101011 1101110 1101111 1110111


Write a Program to convert decimal number into hexadecimal no without using function and string?

This is not a question.


Write a C program to convert hexadecimal number into decimal number?

pongada punda vayanungala ..................


How do you write 20 in binary?

Decimal 20 is 10100 in binary


How do you write binary number 28?

Decimal 28 is 11100 in binary


How do you write the number 212 in binary numbers?

212 (decimal) is 11010100 (binary)


Write a program in C to convert a binary number to its decimal equivalent?

#include#includemain(){int i,j=0,k;printf("enter u r binary number");scanf("%d",&i);while(i>0){k=i/10; // reminderi=i%10;// for dividentj=j+(k*pow(2,k));conversion function}printf("decimal number is :%d",j);}


Why are these octal codes used instead of decimal system?

Octal codes are often used to write the numerical value of a binary number because it is easier to convert from binary to octal, instead of binary to decimal. You can convert to octal on sight, and it simply requires grouping the binary bits into groups of three, whereas converting to decimal requires repeated division by 10102 or 1010. Actually, grouping into three bits is the same as dividing by 1002 or 810 so the process is really the same. Divide by 8 to get octal. Divide by 10 to get decimal.


Write a program to convert the decimal to binary conversion by using while statement?

#include<stdio.h> #include<conio.h> void main() { int num_dec,num_bin[10],i=0; printf("\nEnter the number in Decimal : "); scanf("%d",&num_dec); while(num_dec>0) { num_bin[i]=num_dec%2; num_dec/=2; i++; } i--; printf("\n Binary equivalent is : "); while(i>=0) { printf("%d",num_bin[i]); i--; } getch(); }