‫Hello my friends, and welcome to coding Exercise number three.
‫In this exercise, we are asked to write a program to convert a decimal number to binary number.
‫A decimal number.
‫The decimal numeral system is a standard system for denoting integer and non integer numbers.
‫It's also called base ten positional numeral system, which is the number one, two, three, five,
‫and so on Binary numbers and additional digital electronics and make a mathematics.
‫A binary number is a number expressed in base two numeral system or binary numeral system.
‫This system uses only two symbols, typically one and zeros.
‫So for example, if you input a decimal number five, it will give you a result of 1101.
‫This is the decimal is five, the binary is one one.
‫Let's jump into the ID, but first please post the video and think about how to solve this problems.
‫So I hope you solve it well.
‫Inside the main method I will create and decimal number.
‫And here is the quotient
‫and I equal to one and j.
‫These are the four integers.
‫I need to create a binary array called by num.
‫Ray.
‫Equal to new and of 100.
‫Size 100.
‫Then I use the scanner scan.
‫Or as one equal to new scanner system dot And don't miss to add this line if the error on the scanner
‫stalls.
‫So you need to import the package and class of the scan system dot alt dot print l and enter the decimal
‫number.
‫When the user enters the decimal number, I need to store it inside this number.
‫Variables can dot or s one dot next int
‫now quotient equal to decimal number.
‫I am initializing et while quotient.
‫The code quotient does not equal to zero.
‫I'm not evaluating it to zero.
‫If the quotient does not equal to zero, then number at index I plus plus is equal to quotient.
‫Module two.
‫So what I'm doing here.
‫Quotient equal to quotient over two.
‫First of all, I am getting the binary number at index I plus plus I increased by one and getting that
‫the next digit at index.
‫At this index and quotient, I'm going to get this quotient which is the decimal number.
‫I am dividing it and the remainder I'm storing it inside this binary num array.
‫So this binary num array I am getting its index at i plus plus is equal to the quotient.
‫The remainder of the quotient of this decimal number over two.
‫If you understand the decimals and the binary numbers, how to convert them, how to convert these two
‫numbers from decimal to binary and binary to decimal.
‫You will understand this exercise because you need always do divide over two.
‫Here we are storing the remainder and here we are storing the result of the quotient.
‫The quotient now is equal to quotient over two, so the new quotient variable is equal to quotient.
‫The old quotient over two.
‫So think about quotient is equal to ten over two, which is five.
‫Now I will display when the when the the loop on this loop will end.
‫System dot out dot print l gn.
‫Binary binary number is.
‫And I will put here for J equal to I minus one.
‫J greater than zero and the J minus minus.
‫Here I am printing out the array, then none at index j I am dividing every digit on its own.
‫Over to the remainder will be so it will be stored inside the bin and none at Index II plus plus, and
‫the quotient will be updated by the new quotient over to system.
‫System doled out dough to print l.
‫N.
‫To lines or a new line.
‫Don't worry if I run the program now with coverage.
‫It will give me an enter a decimal number.
‫I will enter five.
‫It should print for me.
‫One, one enter.
‫And here we go.
‫Binary number is 101.
‫This is how we solve this problem, how we get how we get a decimal number from the user and transform
‫it into a binary number.