Convert an Integer to a Binary value in R Programming – as.binary() Function
Last Updated :
16 Jun, 2020
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:
library(binaryLogic)
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:
library(binaryLogic)
x1 < - c( 1 , 10 , - 1 , 2 , 5 )
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
Share your thoughts in the comments
Please Login to comment...