how isolate?
조회 수: 2 (최근 30일)
이전 댓글 표시
hi, I converted decimal no. (10) into binary using x=dec2bin(10,15)=000000000001010
i want to isolate each 5 bits alone, then convert it again into decimal . I don't know how isolate each 5 bits alone.
thanks
댓글 수: 0
채택된 답변
Jan
2011년 10월 21일
v = 10;
x = dec2bin(v, 15); % '000000000001010'
y = transpose(reshape(x, 5, 3)); % ['00000'; '00000'; '01010']
bin2dec(y) % [0, 0, 10]
Or without the slow step over the binary string:
floor(rem(v ./ [1, 32, 32*32], 32))
댓글 수: 0
추가 답변 (1개)
Matt Tearle
2011년 10월 21일
Can you clarify your question? If you want to extract portions of x you can just index:
x(1:5)
x(6:10)
x(11:15)
You could even reshape into 5-character blocks: reshape(x,5,[])'
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 String에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!