I just realized, to check if a number is odd on a cpu, shift the number down. If the shift underflow flag is true, the number is odd....
i just had to write this down somewhere, i feel completely stupid.
<3
-GG34
I feel like that everyday when I come on this site.
HOORAY EVERYONE LETS CLAP FOR GG!
Side note: I didn't know you could do that either. Thanks for that tip
I was working on a new CPU last night, and it just hit me. Literally was a slap to my face, i screamed out loud in my dorm room that im a fucking idiot, the decided to share my new found knowledge here, because if i posted it on 4chan, it could wind up in the wrong hands.
I dont know much about CPU logic, but cant you just check if there's a 1 in the 1s column without the shift?
(09-23-2014, 03:22 AM)greatgamer34 Wrote: [ -> ]I just realized, to check if a number is odd on a cpu, shift the number down. If the shift underflow flag is true, the number is odd....
i just had to write this down somewhere, i feel completely stupid.
<3
-GG34
:3
(09-23-2014, 11:33 PM)RekcirBrickeR Wrote: [ -> ]I dont know much about CPU logic, but cant you just check if there's a 1 in the 1s column without the shift?
that would require more hardware. Im just reusing hardware that i already have
I believe in most CPUs, shifting and checking a flag takes more cycles than a conditional flag AND with 1. Shifting also requires more memory
Also, you could already have a 1 bit even/odd register already setup that automatically fills with the lowest digit, which you just call for in the program. That knocks out running a conditional check and is faster than the shift technique.
I guess I'll clarify, it's not like a true register, the last line just has a duplicate that goes to it's own read address.
You can also call a bit mask of 00000001 (assuming 8 bit) and if you get a zero, you have an even number.