📜  在 R 编程中将整数转换为位 - intToBits()函数

📅  最后修改于: 2022-05-13 01:55:20.234000             🧑  作者: Mango

在 R 编程中将整数转换为位 - intToBits()函数

R 语言中的intToBits()函数用于将整数转换为位,即 0 和 1。输出的长度是整数向量长度的 32 倍。

示例 1:

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

输出:

[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

示例 2:

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

输出:

[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