i have a single row vector contains 0s and 1s and want to convert every 3 bits into integer how can i do that??
1 次查看(过去 30 天)
显示 更早的评论
i have a single row vector contains 0s and 1s and want to convert every 3 bits in this vector into integer how can i do that??
i have single row vector contains 0s and 1s values and i need every 3 bits in this vector convert to decimal number
for example
x=[0 1 0 1 1 1 ]
then i want this single row to be converted to decimel every 3 of them to decimal [010],[111]
0 个评论
采纳的回答
Mathieu NOE
2022-4-22
hello
see below
hope it helps
% dummy data
nbits = 3;
samples = 8;
x = round(rand(1,nbits*samples));
nbits_vect = 2.^((nbits-1:-1:0));
%%%% main loop %%%%
iter = fix((length(x)-nbits)/nbits +1);
for ci=1:iter
start_index = 1+(ci-1)*nbits;
stop_index = min(start_index+ nbits-1,length(x));
int_data(ci) = sum(nbits_vect.*x(start_index:stop_index)); % your interger data
end
figure(1),
plot(int_data,'r'); % your interger data
6 个评论
Bruno Luong
2022-4-24
编辑:Bruno Luong
2022-4-24
it's equivalent to the sequence
[100,10,1] but in base 2.
更多回答(2 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!