How to alter a bit
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Jan
il 14 Feb 2023
@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.
Risposte (1)
Steven Lord
il 9 Feb 2023
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 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!