当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R语言 intToBits()用法及代码示例


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

用法: intToBits(x)

参数:
x:整数或整数向量

范例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

相关用法


注:本文由纯净天空筛选整理自nidhi_biet大神的英文原创作品 Convert an Integer to Bits in R Programming – intToBits() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。