How do you subtract/add with roll under/over
Mostrar comentarios más antiguos
When you subtract two uint numbers together example:
uint8(1) - uint8(2)
I would like the answer to be 255, instead no matter what the value MATLAB returns 0, likewise if you try adding:
uint8(255) + uint8(1)
MATLAB returns 255.
I have written my own add and subtract functions for this purpose which work fine but I am wondering whether there is actually something in built that I am missing. If there is could you please point me in the right direction.
Thanks.
1 comentario
Matthew Doveton
el 19 de Ag. de 2013
Respuestas (2)
Azzi Abdelmalek
el 19 de Ag. de 2013
Editada: Azzi Abdelmalek
el 19 de Ag. de 2013
Edit
a=uint8(-1);
out=uint8(255)*uint8(not(a))+a
2 comentarios
Matthew Doveton
el 19 de Ag. de 2013
Azzi Abdelmalek
el 19 de Ag. de 2013
Editada: Azzi Abdelmalek
el 19 de Ag. de 2013
Look at edited answer
Sean de Wolski
el 19 de Ag. de 2013
Editada: Sean de Wolski
el 19 de Ag. de 2013
x = uint8(1);
y = uint8(2);
z = max(double(x)-double(y),0)+uint8(x < y).*255
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!