kotlin 二进制
We are given a decimal number and we will create a Kotlin program to convert decimal number to binary.
我们给了十进制数,我们将创建一个Kotlin程序将十进制数转换为二进制 。
To convert decimal number to binary, we will recursively divide the decimal number by 2 and save the remainder found till the decimal number vanquishes.
要将十进制数转换为二进制,我们将十进制数递归除以2,然后将找到的余数保存到十进制数消失。
Example:
例:
Input:
Decimal number = 12
Recursive division:
Number | Quotient | Remainder |
---|---|---|
12 | 6 | 0 |
6 | 3 | 0 |
3 | 1 | 1 |
1 | 0 | 1 |