필터 지우기
필터 지우기

Binary string to vector

조회 수: 48 (최근 30일)
Martin Park
Martin Park 2013년 10월 8일
댓글: Walter Roberson 2017년 8월 25일
Can anybody help me to convert a binary string for example 0001101 into a vector. when using str2num the first 0's are thrown away
  댓글 수: 1
Jan
Jan 2013년 10월 8일
If you mean a string, set it is quotes as usual in Matlab.

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

채택된 답변

Image Analyst
Image Analyst 2013년 10월 8일
s = '0001101'
out = s-'0'
  댓글 수: 2
Hao Sun
Hao Sun 2017년 8월 25일
can you please explain how this works?
Walter Roberson
Walter Roberson 2017년 8월 25일
There was a time, quite very early on in electronic computing, when the numerals were represented in adjacent positions in the character set, in the order '1', '2', '3', '4', '5', '6', 7', '8', '9', '0' . That time is long long gone, and for well over 60 years all character sets have represented the numerals as adjacent positions in the character set, in the order '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' .
There have been character sets such as IBM's EBCDIC that put those characters in different starting point than is now standard.
No matter where the block of numerals is in the character set, if you can be sure you are not working with 1940's character sets, then you can figure out the decimal value of the '0' or '1' characters by figuring out the offset from the '0' character, by subtracting the internal representation of the '0' character. '0'-'0' is 0, which is what you would want in decimal, and '1'-'0' is 1 because '1' is known to be the character immediately adjacent to the '0' character.

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

추가 답변 (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