Kureb
Kureb

Reputation: 76

Convert logical to char (still binary) class

I have this structure

Name      Size            Bytes  Class      Attributes
txt        8x7            56     logical 

8×7 logical array
0   1   0   1   0   0   1
0   0   1   1   0   1   0
0   0   0   1   1   0   1
1   1   0   1   1   1   0
1   1   0   0   0   0   1
1   1   0   1   1   0   1
0   1   0   1   1   1   0
1   1   1   0   1   0   1

that I want to convert into that one

Name         Size            Bytes  Class    Attributes
txt_bin      8x7             112    char

1010110
1100101
1110010
1101110
1100001
1101101
0101110
0001010

Both are the same "size". I want the second structure so I will be able to get the text through char(bin2dec(txt))

Is there a well-known function? I tried unsuccessfully with some reshape..

To clarify the context, I have a clear text that I convert to binary, so I can make a XOR with a passphrase (Vernam crypto), and now I want to transcript this new binary result into char to be able to send the encrypted message.

Thanks for the help

Upvotes: 0

Views: 335

Answers (1)

rahnema1
rahnema1

Reputation: 15857

txt = logical([...
0   1   0   1   0   0   1
0   0   1   1   0   1   0
0   0   0   1   1   0   1
1   1   0   1   1   1   0
1   1   0   0   0   0   1
1   1   0   1   1   0   1
0   1   0   1   1   1   0
1   1   1   0   1   0   1]);
ch = '01';

txt_bin = ch([~txt(1:3,:);txt(4:7,:);~txt(8,:)] + 1)

or

char([~txt(1:3,:);txt(4:7,:);~txt(8,:)]+'0')

Upvotes: 3

Related Questions