Convert an Integer to a Binary value in R Programming – as.binary() Function
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:
# R Program to convert# an integer to binary # Loading librarylibrary(binaryLogic) # Calling as.binary() functionas.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:
# R Program to convert# an integer to binary # Loading librarylibrary(binaryLogic) # Creating a vectorx1 <- c(1, 10, -1, 2, 5) # Calling as.binary() functionas.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





Please Login to comment...