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
相關用法
- R語言 as.integer()用法及代碼示例
- R語言 is.integer()用法及代碼示例
- R語言 strtoi()用法及代碼示例
- R語言 utf8ToInt()用法及代碼示例
- R語言 intToUtf8()用法及代碼示例
- R語言 as.binary()用法及代碼示例
- R語言 type.convert()用法及代碼示例
- R語言 toupper()用法及代碼示例
- R語言 charToRaw()用法及代碼示例
- R語言 dQuote()用法及代碼示例
- R語言 sQuote()用法及代碼示例
- R語言 deg2rad()用法及代碼示例
- R語言 rad2deg()用法及代碼示例
- R語言 str_to_title()用法及代碼示例
- R語言 as.factor()用法及代碼示例
- R語言 as.ordered()用法及代碼示例
- R語言 as.list()用法及代碼示例
- R語言 data.matrix()用法及代碼示例
- R語言 as.character()用法及代碼示例
- R語言 as.logical()用法及代碼示例
- R語言 as.Date()用法及代碼示例
- R語言 as.vector()用法及代碼示例
- R語言 as.matrix()用法及代碼示例
注:本文由純淨天空篩選整理自nidhi_biet大神的英文原創作品 Convert an Integer to Bits in R Programming – intToBits() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。