MATLAB Answers

How to divide 8 bit binary into two 4 bit?

조회 수: 6(최근 30일)
sami ullah
sami ullah 24 Oct 2020
댓글: sami ullah 25 Oct 2020
For example A=11001111,
i want to break it as A1=1100 and A2=1111.
How it can be done in matlab?

  댓글 수: 0

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

채택된 답변

madhan ravi
madhan ravi 24 Oct 2020
A = '11001111'
A = mat2cell(A, 1, [4, 4]);
celldisp(A)

  댓글 수: 3

madhan ravi
madhan ravi 24 Oct 2020
Or:
A = num2cell(reshape(A, 4, []).', 2);
celldisp(A)
sami ullah
sami ullah 25 Oct 2020
If i change A to like this
A = '1100'
A = mat2cell(A, 1, [4, 4]);
celldisp(A)
it gives the following error
Error using mat2cell (line 97)
Input arguments, D1 through D2, must sum to each dimension of the input matrix size, [1 4].'
I need output like this
A1=0000
A2=1100
sami ullah
sami ullah 25 Oct 2020
I did it as:
N=12;
A=dec2bin(A,8)
A=mat2cell(A, 1, [4, 4]);
celldisp(A)
And it is done
Thanks

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by