function for addition 2^16 modulo
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Saranya Krishnamurthy
el 17 de Abr. de 2021
Comentada: Saranya Krishnamurthy
el 20 de Abr. de 2021
Addition modulo (denoted with a boxed plus ⊞)
what is the command for 2^16 addition modulo: a ⊞ b?
Can someone help?
2 comentarios
Respuestas (2)
Bjorn Gustavsson
el 19 de Abr. de 2021
Just make sure that your ints a and b are in int32 or larger number of bit-formats, then use:
C = mod(a+b,2^16)
HTH
John D'Errico
el 19 de Abr. de 2021
Editada: John D'Errico
el 19 de Abr. de 2021
Your numbers are in BINARY form, and you want to add modulo 2^16.
The simplest solution is to convert to a decimal integer. I'll assume they are stored as chars. But if they are boolean vectors, just as easy.
A = '101100110001';
B = '10010000001';
AplusB = mod(bin2dec(A) + bin2dec(B),2^16) % as a base 10 integer result
AplusB = dec2bin(AplusB)
You can do it all in one line. Or, you could even write a little function.
binplus16 = @(a,b) dec2bin(mod(bin2dec(A) + bin2dec(B),2^16));
binplus16(A,B)
As you can see, the result is the same. We could have done it in a variety of ways. But this is simplest.
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!