Reference Materials
Certification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
Convert Decimal into Binary using Recursion in R
In this example, you will learn to convert decimal number into binary by creating a recursive function, convert_to_binary().
Example: Binary to Decimal
# Program to convert decimal
# number into binary number
# using recursive function
convert_to_binary <- function(n) {
if(n > 1) {
convert_to_binary(as.integer(n/2))
}
cat(n %% 2)
}
Output
> convert_to_binary(52) 110100
In this program, we convert decimal number entered by the user into binary using a recursive function.
Decimal number is converted into binary by dividing the number successively by 2 and printing the remainder in reverse order.