Last active
March 1, 2017 21:33
-
-
Save giraffesyo/1df5becab4d434f8e02c4544df3346f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//q = b/a | |
division(int a, int b) | |
{ | |
q = 0; //quotient | |
r = b; //remainder | |
bit = 1; | |
while ( a < r) | |
{ | |
a = a << 1; | |
bit = bit<<1; | |
} | |
while ( bit >= 1) | |
{ | |
if (a < r) { | |
r = r - a; | |
q = q + bit; | |
} | |
bit = bit>> 1; | |
a = a >> 1; | |
} | |
} | |
//Want to divide 1100111 by 110 | |
// so what I do then is see the first place it fits, then subtract, and bring down remaining digits. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//p = a*b | |
//p = (a_0)*(b<<0) + (a_1)*(b<<1) ... | |
int mult(int a, int b) | |
{ | |
int p = 0; | |
for (int i = 0; i < 32; i++) | |
{ | |
if((a>>i) & 1 ) != 0) | |
p += b << i; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment