Skip to content
Related Articles

Related Articles

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to convert an integer to bits
  
# Calling the intToBits() function
intToBits(0)
intToBits(1)
intToBits(2)

chevron_right


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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to convert an integer to bits
  
# Creating a vector
x <- c(0, 1, 2)
  
# Calling the intToBits() function
intToBits(x)

chevron_right


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
My Personal Notes arrow_drop_up
Recommended Articles
Page :