Open In App

Convert an Integer to a Binary value in R Programming - as.binary() Function

Last Updated : 16 Jun, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
as.binary() function in R Language is used to convert an integer value to a binary value.
Syntax: as.binary(x) Parameters: x: Integer value
Example 1: Python3 1==
# R Program to convert
# an integer to binary

# Loading library
library(binaryLogic)

# Calling as.binary() function
as.binary(1)
as.binary(10)
as.binary(-1)
as.binary(0xAB)
Output:
[1] 1
[1] 1 0 1 0
[1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[1] 1 0 1 0 1 0 1 1
Example 2: Python3 1==
# R Program to convert
# an integer to binary

# Loading library
library(binaryLogic)

# Creating a vector
x1 <- c(1, 10, -1, 2, 5)

# Calling as.binary() function
as.binary(x1)
Output:
[[1]]
[1] 1

[[2]]
[1] 1 0 1 0

[[3]]
 [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

[[4]]
[1] 1 0

[[5]]
[1] 1 0 1

Next Article
Article Tags :

Similar Reads