Convert an Integer to Bits in R Programming – intToBits() Function
intToBits()
function in R Language is used to convert an integer into Bits i.e. 0s and 1s. The output is of length 32 times the length of integer vector.
Syntax: intToBits(x)
Parameters:
x: Integer or integer vector
Example 1:
# R program to convert an integer to bits # Calling the intToBits() function intToBits( 0 ) intToBits( 1 ) intToBits( 2 ) |
Output:
[1] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [26] 00 00 00 00 00 00 00 [1] 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [26] 00 00 00 00 00 00 00 [1] 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [26] 00 00 00 00 00 00 00
Example 2:
# R program to convert an integer to bits # Creating a vector x < - c( 0 , 1 , 2 ) # Calling the intToBits() function intToBits(x) |
Output:
[1] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [26] 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [51] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 [76] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00