How to alter a bit
조회 수: 2 (최근 30일)
이전 댓글 표시
iam having a 5*1 cell. Now each cell contains two or more elements.I need to alter a single different bit between two elements. The first row in cell has two elements which differ by a single bit. So the output is expected to be 10010. The second row in cell has two elements which differ by a single bit. So the output is expected to be 11000. The third row consists of five elementsnow each element has to be compared against the remaining elements. first element and last element in 3rd row differs by one bit so the expected output is 10111 similarly 2nd element and last element differs by 1 bit so the expected output is 10111. the remaining 2 elements in 3rd row cannot be merged. 3rd row in the expected output has elements 10111,1100,1011. similar procedure has to be followed for remaining two rows in the cell. Thank you in advance.
For Example:
A =[ [10010;10000]
[1000;11000]
[111;10011;1100;1011;10111]
[1010;11010]
[1111;1110] ]
Expected Output:
B = [ [ 10010]
[11000]
[10111;1100;1011]
[11010]
[1111] ]
댓글 수: 6
Jan
2023년 2월 14일
@barath manoharan: Now I've lost the overview completely. I have no idea, what the format of your inputs is. after discussing this important detail for 5 days now, I assume, that I cannot help you.
답변 (1개)
Steven Lord
2023년 2월 9일
I agree with Jan that the actual format of your data is not clear to me. In the first block of code below A does not contain the values whose binary representation are 10010, 10000, etc.
A =[ [10010;10000]
[1000;11000]
[111;10011;1100;1011;10111]
[1010;11010]
[1111;1110] ]
If you're entering your data in the Command Window or in a MATLAB program file you can make them the values with those binary representations using the 0b prefix.
B = [0b10010, 0b10000]
bitget(B, 5)
bitget(B, 2)
bitget(B(1), 5:-1:1)
C = bitset(B, 3, 1)
dec2bin(B)
dec2bin(C) % These differ from the display of B due to the bitset call
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!