當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。