If you want to start learning the R programming or you have a bit knowledge about R programming, then this tutorial will help you to explore more. In this tutorial, we are going to share a Convert decimal into binary using recursion in R with an example.
In this program, convert a decimal number into a binary number entered by the user using a recursive function.
Try more:
Copy the below code and execute it to see the program output.
1 2 3 4 5 6 | convert_to_binary <- function(n) { if(n > 1) { convert_to_binary(as.integer(n/2)) } cat(n %% 2) } |
convert_to_binary(52)
110100
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.