Binary to ASCII Conversion
古いコメントを表示
Hi,
I have message of 1x5120 double (binary values 0 and 1). I have to convert this to ASCII. I am supposed to use below method. Can anyone let me know what is the error in the below code, Thanks.
ASCII_1 = Message(1,1:10)*(2.^[0:9])';
u = Message(1,Nsc+1:end);
wh=2.^[6:-1:0];
m=char(u(1:7)*wh');
for k=1:1:ASCII_1
m=[m char(u(7*(k-1)+1:7*k)*wh')];
end
disp(m)
Note: Message is 1x5120 double
5 件のコメント
Geoff Hayes
2021 年 10 月 9 日
@Darshan Manjunathrao Chawan - is this your code or someone elses? If your code, can you comment to indicate what you are attempting? Are you assuming that each consecutive set of 8 bits corresponds to a single ASCII character? And so your 1x5120 binary array should correspond to a 640 character message?
Also, what is Nsc?
Darshan Manjunathrao Chawan
2021 年 10 月 9 日
編集済み: Darshan Manjunathrao Chawan
2021 年 10 月 9 日
Geoff Hayes
2021 年 10 月 9 日
Since your code, can you add some comments to it? Also, is one ASCII character represented by 8 bits? If so, how do you take that into account in your code?
Darshan Manjunathrao Chawan
2021 年 10 月 9 日
編集済み: Darshan Manjunathrao Chawan
2021 年 10 月 9 日
David Hill
2021 年 10 月 9 日
You need to know how the message was transmitted for example:
a='cat in hat';
t=dec2bin(double(a),8)';%we are assuming each character is forced to be 8 bits (it is important to know)
t=t(:)'-'0';%we are assuming this is the stream you are getting, but it could be flipped depending on how it was transmitted.
If the above is the case, decoding is as simple as:
r=num2str(t);
r=char(bin2dec(reshape(r(r~=' '),8,[])'))';
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Standard File Formats についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!