Convert an Integer to Bits in R Programming – intToBits() Function
Last Updated :
16 Jun, 2020
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:
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:
x < - c( 0 , 1 , 2 )
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...