gpt4 book ai didi

r - 如何将r中的矩阵中的十六进制转换为二进制?

转载 作者:行者123 更新时间:2023-12-02 03:31:36 25 4
gpt4 key购买 nike

我有一个十六进制数的矩阵,如下所示:

       [,1] [,2] [,3]
[1,] "FA" "F8" "D0"
[2,] "CE" "17" "6A"
[3,] "0E" "D6" "22"

如果我尝试转换为二进制,使用 hex2bin(matrix) (library BMS) 给我:

  [1] 1 1 1 1 1 0 1 0 0 0 0 0 1 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 0 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0
[62] 0 0 1 0 1 1 1 0 0 0 0 1 1 0 1 0 1 1 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 0 0 0 0 0 0 0
[123] 1 0 0 0 1 0 0 0 0 0 1 1 1 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 1 0 0 0 0 0 0 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0
[184] 1 0 0 0 1

但是需要一个矩阵。

最佳答案

也许像这样?我使用内置的 strtoi 转换为十进制整数,然后从 Converting decimal to binary 获取提示。用于获取二进制文件。

m = matrix(c("FA", "F8", "D0",
"CE", "17", "6A",
"0E", "D6", "22"), 3)

m[] = R.utils::intToBin(strtoi(m, base = 16L))
m
# [,1] [,2] [,3]
# [1,] "11111010" "11001110" "00001110"
# [2,] "11111000" "00010111" "11010110"
# [3,] "11010000" "01101010" "00100010"

关于r - 如何将r中的矩阵中的十六进制转换为二进制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51714944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com