Open In App

Convert an Integer to Bits in R Programming – intToBits() Function

Last Updated : 16 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads