Post History
#2: Post edited
- I am giving Python code.
- ```python
- # Function to convert decimal number
- # to binary using recursion
- def DecimalToBinary(num):
- if num >= 1:
- DecimalToBinary(num // 2)
- print(num % 2, end = '')
- # Driver Code
- if __name__ == '__main__':
- # decimal value
- dec_val = 24
- # Calling function
- DecimalToBinary(dec_val)
- ```
- ![conversion](https://math.codidact.com/uploads/YJ1fiAVd3iaxK7ZfHN5CXxGS)
I hope it is understandable. Keep diving until you get zero. And, note every remainders. Remainders is binary.
- I am giving Python code.
- ```python
- # Function to convert decimal number
- # to binary using recursion
- def DecimalToBinary(num):
- if num >= 1:
- DecimalToBinary(num // 2)
- print(num % 2, end = '')
- # Driver Code
- if __name__ == '__main__':
- # decimal value
- dec_val = 24
- # Calling function
- DecimalToBinary(dec_val)
- ```
- ![conversion](https://math.codidact.com/uploads/YJ1fiAVd3iaxK7ZfHN5CXxGS)
- I hope it is understandable. Keep diving until you get zero. And, note every remainders. Remainders is binary.
- Note : sometime some computers use 0 before binary. E.g. binary of 85 is 1010101 but, some computer will write 01010101.
- I think it happens for encoding. Any computer can decode both and, return same value.
#1: Initial revision
I am giving Python code. ```python # Function to convert decimal number # to binary using recursion def DecimalToBinary(num): if num >= 1: DecimalToBinary(num // 2) print(num % 2, end = '') # Driver Code if __name__ == '__main__': # decimal value dec_val = 24 # Calling function DecimalToBinary(dec_val) ``` ![conversion](https://math.codidact.com/uploads/YJ1fiAVd3iaxK7ZfHN5CXxGS) I hope it is understandable. Keep diving until you get zero. And, note every remainders. Remainders is binary.