2

I have an matrix with hexadecimal number, like that:

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

If I try convert to binary, with hex2bin(matrix) (library BMS) give me:

  [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

But need a matrix.

Márcio Mocellin
  • 274
  • 5
  • 18

1 Answers1

5

Maybe like this? I convert to decimal integer using the built-in strtoi, then take cues from Converting decimal to binary for getting 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"
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294