How to convert a binary string to binary number?
조회 수: 25 (최근 30일)
이전 댓글 표시
Kiran Bhageerath Reddy Vuyurru
2021년 1월 31일
댓글: Walter Roberson
2021년 2월 2일
Hello
I wanted to convert a string of binary number to just a binary number(not array)
For example:
if this is a input binary_string = '00110110101'
expected_output = 00110110101
댓글 수: 0
채택된 답변
Walter Roberson
2021년 1월 31일
binary_string = '00110110101'
expected_output = uint16(bin2dec(binary_string));
expected_output
This is the base 10 display of a binary number whose bit pattern is 000000110110101
MATLAB has no built-in facility to create binary numbers that automatically display in binary format.
Is it possible that what you want is the base 10 number that MATLAB would output as 110110101, decimal one hundred and ten million, one hundred and ten thousand, one hundred and one ? Note that MATLAB will never automatically display leading zeros on a decimal number (after all, there are an infinite number of leading zeros.)
댓글 수: 2
Walter Roberson
2021년 2월 2일
When you have a vector of characters, then bit shifting corresponds to circshift() if you are using rotation, or to throwing away columns at the end if you are shifting right, or to adding columns of '0' at the right if you are shifting left.
I do not know what a "real number" is in this context. If you have a double precision number you need to convert to single precision, then use single()
format long g
p = pi
ps = single(p)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!