Bit stream in to digits

8 次查看(过去 30 天)
Raza
Raza 2014-2-19
i have a stream of bits(1 and o), when i save these bit , like i have 128 bits, b1 contains 1 to 10 bits, b2 contain 11 to 20 and so on. Now i got a problem that when i save these bits in b1, b2 , b3 and so on. and want to retrieve, it gives value instead of binary digits, so to solve this issue, i used bitget command but it only support 52 digits, while my requirement is 128
  4 个评论
Jos (10584)
Jos (10584) 2014-2-19
Please elaborate ...
Raza
Raza 2014-2-19
i have a stream of bits (1 and 0) , let assume its length is 40. now using for loop i am saving first ten bits in b1, next ten bits in b2 and so on...

请先登录,再进行评论。

采纳的回答

Mischa Kim
Mischa Kim 2014-2-19
Raza, you can retrieve the bit pattern by concatenating the cell strings:
[r, c] = size(b);
bit_stream = [];
for ii = 1:c
bit_stream = strcat(bit_stream,b{ii});
end
disp(bit_stream)
  2 个评论
Jos (10584)
Jos (10584) 2014-2-19
STRCAT can concatenate an infinite number of arguments. In Mischa's nice answer you can exploit comma-separate list expansion and get rid of the for-loop:
b = {'101','000','111','010','101'} % shortened example
bitstream = strcat(b{:})
Raza
Raza 2014-2-19
编辑:Raza 2014-2-19
Thanks man, but still got a problem, let me tell u complete detail. i am taking text as a input then i am converting this text into 8 bit binary. and these 8 bits are combined. now i want to separate 128 bits. for example i have text entered "Matlab is good language for coding." and in bits form it is "0101010100010010100100010100100101010101001010..." let assume its length is 256. now i want 128 128 block of bits? i am just stuck in last part

请先登录,再进行评论。

更多回答(1 个)

Jos (10584)
Jos (10584) 2014-2-19
You can split the string into cells
% (smaller) example
MyStr = '10100101010101010010101010101010' ; % a string of arbitrary length
N = 5 ; % the size of each block (in your case 128).
maxN = numel(MyStr)
ix0 = 1:N:maxN
fh = @(X) MyStr(X:min((X+N-1),maxN))
B = arrayfun(fh,ix0,'un',0)
% now B{K} holds the K-th block of N bits of S
MyStrToo = cat(2,B{:})
isequal(MyStrToo, MyStr) % check!

类别

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