+ 1
Make an algorithm to convert decimal into binary
can u do this
8 Respostas
+ 2
sam
0. We import LinkedList and Scanner from the java.util package.
1. We create an instance of the scanner.
2. It takes a number input from the user.
2. It checks whether it is a number or not.
3. If it isn't, error message is printed.
4. Else, the conversion process begins.
5. We define a number "b" and assign the value of the input into it.
6. We define a boolean "c".
7. If the input is a positive number, this boolean will be true.
8. Else, it'll be false.
9. Regardless of the boolean value, b is made a positive number.
10. We create a new String LinkedList.
11. We define a number "n" and assign 64 to it.
12. We divide b by 2^n and add the result into the LinkedList, and decrease b from the remainder.
12a. n is decremented by 1.
12b. We go back to step number 12 until n reaches zero.
13. We define a new String for the output.
14. We pack the entire LinkedList value into the String.
15. We take the boolean mentioned in step 6.
16. If it is true, nothing happens.
17. If it is false, we add "-" to the beginning of the String.
18. The String is returned as a result.
19. The String is printed.
I hope this helps âș
+ 1
can u give me the algorithm of this
+ 1
Ibaadi Jaya đ
+ 1
Here is a simple algorithm:
1. Divide decimal number by 2
2. Note the remainder
3. If the quotient is 0, continue to step 4; otherwise return to step 1 with the quotient as the new decimal number.
4. The remainders sorted from last to first is your binary number
--------------------------------------------------------
For example, let's take the number 10 (in decimal):
10 // 2 = 5 (rem = 0)
5 // 2 = 2 (rem = 1)
2 // 2 = 1 (rem = 0)
1 // 2 = 0 (rem = 1)
['//' means floor division, which means we remove the decimal numbers after the division]
Since the quotient is zero, we can sort the remainders in the order of last to first:
=> 1010
Therefore 1010 is the binary representation of 10.
--------------------------------------------------------
Hope this was of some help :)
+ 1
thank u guys for help me đđđ
0
Please do not plagiarize without crediting my name...
https://code.sololearn.com/cnT9clyEeuo8/?ref=app