I want to convert string to binary equivalent and binary to string

조회 수: 15 (최근 30일)
I want to convert the string to binary equivalent and then again convert the string to binary. I got the code for this
String='This is your sample hidden string.';
binar=reshape(dec2bin(String,8).',1,[])
reconver_str = char(bin2dec(reshape(char(binar+'0'), 8,[]).'))
but i getting the error
Error using bin2dec (line 55)
Binary string may consist only of characters 0 and 1
Error in convstrtobin (line 3)
reconver_str = char(bin2dec(reshape(char(binar+'0'), 8,[]).'))
can anyone please help me how to correct this error.
  댓글 수: 1
Guillaume
Guillaume 2019년 1월 20일
Note that your conversion will only work for char arrays that only contain characters with value 0 to 255. This is a very small subsets of the characters supported by matlab.
Characters in matlab are not 8-bit.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2019년 1월 20일
You forgot to subtract '0'
binar=reshape(dec2bin(String,8).',1,[]) - '0';

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by