Skip to content

Instantly share code, notes, and snippets.

@giraffesyo
Last active March 1, 2017 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giraffesyo/1df5becab4d434f8e02c4544df3346f1 to your computer and use it in GitHub Desktop.
Save giraffesyo/1df5becab4d434f8e02c4544df3346f1 to your computer and use it in GitHub Desktop.
//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.
//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