实际上我正在尝试将十六进制转换为 bin。
a=hex2dec('ab32');
a=dec2bin(a);
%now I have a 1to1 char array of for example 1010101...
%I want to have an 1*16 array of 1 and 0's
我怎样才能做到这一点?
实际上我正在尝试将十六进制转换为 bin。
a=hex2dec('ab32');
a=dec2bin(a);
%now I have a 1to1 char array of for example 1010101...
%I want to have an 1*16 array of 1 and 0's
我怎样才能做到这一点?
你可以这样做:
a=logical(a-'0')
例子:
octave:224> a=hex2dec('ab32')
a = 43826
octave:225> a=dec2bin(a)
a = 1010101100110010
octave:226> a=logical(a-'0')
a =
1 0 1 0 1 0 1 1 0 0 1 1 0 0 1 0
octave:227> whos a
Variables in the current scope:
Attr Name Size Bytes Class
==== ==== ==== ===== =====
a 1x16 16 logical
Total is 16 elements using 16 bytes
octave:228>
这为您提供了一个 1*16 实数向量,全部为 0 或 1:
(dec2bin(hex2dec('ab32'))-'0')
虽然这给了你一个 1*16 的逻辑向量,要么是假的要么是真的(看起来像 0 和 1)
(dec2bin(hex2dec('ab32'))-'0')==1