Divisions with shifts

Miles Bader bader at b.psy.cmu.edu
Thu Jan 9 14:10:25 AEST 1986


Just shifting using an arithmetic shift may give the wrong answer, but
you could correct the rounding and still get much faster execution like:

	shiftRightArithmetic	register
	branchIfPositive	label
	increment		register
label:

so -23/2 = -23>>1 + 1 = 11101001>>2 + 1 = 11110100 + 1 = 11110101 = -11
which is the right answer...

					-Miles



More information about the Comp.lang.c mailing list