フィルターのクリア

how to convert a string to binary and then from the binary back to string

101 ビュー (過去 30 日間)
Elysi Cochin
Elysi Cochin 2016 年 10 月 6 日
コメント済み: marie lasz 2021 年 1 月 5 日
how to convert a string to binary and then from the binary back to string
s = 'Mary had a little lamb';
binary = dec2bin(s);
str = bin2dec(binary)
but str i obtained is not string... how to get the string back... also, when i do above i get binary as char variable...
binary =
1001101
1100001
1110010
1111001
0100000
1101000
1100001
1100100
0100000
is it possible, to get is as a vector, with double datatype and i should be able to get that back as string...
binary =
1 1 0 1 0 0 0 0 1 0

採用された回答

Walter Roberson
Walter Roberson 2016 年 10 月 6 日
binary = reshape(dec2bin(s, 8).'-'0',1,[])
str = char(bin2dec(reshape(char(binary+'0'), 8,[]).'))
  2 件のコメント
Awais Saeed
Awais Saeed 2019 年 5 月 5 日
@Walter Roberson how these two lines are working? I only understand dec2bin and bin2dec.
marie lasz
marie lasz 2021 年 1 月 5 日
@Awais Saeed
s = 'Awais Saeed';
binary = reshape(dec2bin(s, 8).'-'0',1,[]);
display(binary);
str = char(bin2dec(reshape(char(binary+'0'), 8,[]).'));
display(str);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by