Java code for Converting Decimal Number to Binary Number

preview_player
Показать описание
This program demonstrates the logic and code for converting decimal number to binary number
Normal integer number are by default decimal number ( base 10 , which contains digits from 0 to 9), example: 100,34534,-345345.
Every decimal number internally stored as binary number ( base 2, which contains only two digits,i.e. 0 and 1 ).

Converting decimal to binary involves the following steps
1. we need to divide the decimal number by 2 til it reaches to 0
2. In this process we need to store the remainders
3. The remainders must be printed in the reverse order to get the binary representation.

Example : 10 decimal is equivalent to 1010.

In this video session, we have discussed the following approaches to convert decimal to binary
2. Using array to store all the remainders
3. Using String to concatenate all the remainders

If you like this video, don't forget to subscribe , like and share this video

Please promote this channel , by sharing it with your friends who are searching / preparing for IT jobs in programming..

If you have any coding challenges ( questions ) , post them in the comment, we will upload the videos for the same
Рекомендации по теме
Комментарии
Автор

God bless you my friend took me an hour to find how to do with strings once again indian youtuber comes in clutch

cedrikclaus
Автор

crystal clear explanation.thank you sir

simranha
Автор

Thanks for the sake of mankind it helped me thanks again.

MrAmin-pulw
Автор

Sir this program understand clearly, i want binary addition , binary multiplication demonstration Sir

mohanasundari
Автор

Hello! Thanks a lot for the explanation!
I have tried the following but it does not work, I have everytime result = 0. Could you please help me?

public class DecimalToDual {
public static void main(String[] args) {
int decimal = 12;
System.out.println("The number is base2 is " + transformToDual(decimal));
}
public static String transformToDual(int decimal) {
int n = decimal;
String binary = ""; //initialize variable binary
int remainder = decimal % 2;
binary = remainder + binary; //at the beginning the remainder will be concatenated with the empty string (binary) but then it will be start adding nº to it.
n = n / 2;
return binary;
}
}

mariaalarcon
welcome to shbcf.ru