how isolate?

1 次查看(过去 30 天)
huda nawaf
huda nawaf 2011-10-21
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

采纳的回答

Jan
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))

更多回答(1 个)

Matt Tearle
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,[])'

类别

Help CenterFile Exchange 中查找有关 String 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by