其实我正在尝试将hex转换为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
我该怎么做?
答案 0 :(得分:5)
你可以这样做:
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 :(得分:1)
这为你提供了一个1 * 16的实数矢量,都是0或1:
(dec2bin(hex2dec('ab32'))-'0')
虽然这给你一个1 * 16的逻辑向量,都是假的或者是真的(看起来像0和1)
(dec2bin(hex2dec('ab32'))-'0')==1