Can rem function be used for binary variables

조회 수: 1 (최근 30일)
Shashi
Shashi 2015년 5월 20일
댓글: Shashi 2015년 5월 20일
b = 0; c = dec2bin(b,4); d = rem(c,10);
The answer is d = 8 8 8 8
Can anyone please explain the reason why it is giving such an output and how?

채택된 답변

Guillaume
Guillaume 2015년 5월 20일
dec2bin does not generate a number, but a string. You're calculating the remainder of the ascii code of the characters '0' and '1' divided by the decimal 10 (and not binary 10 == decimal 2).
The only numeric representation that matlab understands is decimal. All other representations use strings. Numerical operations applied to strings use the ascii code of the characters.
The closest you could come to the result you want would be:
b = 0;
d = dec2bin(rem(b, bin2dec('10'))
  댓글 수: 1
Shashi
Shashi 2015년 5월 20일
Thank you. I understood how the answer was obtained. Your answer is helpful.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by