资源描述
单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,*,/12,*,3.4,二进制除法运算(原码),0.111,0.1011 0.1010,0,R,0,-0.0101 1,-2,-1.,Y,0.0100 1,0,R,1,-0.0010 11 -2,-2.,Y,0.0001 11,0 R,2,-0.0001 011 -2,-3.,Y,0.0000 011,0 R,3,例:,X,0.1010,,,Y,0.1011,,人工计算,X/Y,。,每一步都要比较,余数,R,i-1,与,-2,-i.,Y,的,大小。,注意:,若,R,i-1,2,-i,.Y0,,,表示够减,商为,1,;,反之,商为,0,。,1,1,/12,被除数,(,余数,),除数时,可能产生,负余数,,,对负余数有两种不同的处理方法。,依据对负余数的处理方法,对应有两种除法,运算方法:,恢复余数法,不,恢复余数法,(,加减交替法,),(,常用,),两个原码数相除,其商的符号为两数符号的,异或值,数值则为两数绝对值相除后的结果。,2,2,/12,一、原码恢复余数法,每一步须比较上一步的余数,R,i-1,和,2,-i,Y,的大小,,人工计算时计算者可用观察比较的办法确定商,上,0,还是,1,,而在计算机中,只能用做减法判断,结果的符号为负还是为正来确定。,若,R,i-1,2,-i.,Y,0,,则上商,1,,差值即为余数,R,i,;,若,R,i-1,2,-i.,Y,0,,则上商,0,,差值并不是余数,R,i,,,要恢复,R,i,为上一步的余数,R,i-1,,即,R,i,2,-i.,Y,。,3,3,/12,Y,用,Y,补,实现。,改进:,笔算时,是余数不动,除数逐次右移;机器运算时,,改为除数不动,余数逐次左移。,左移出界的余数的高位都是无用的零,对运算不会,产生任何影响。,由于每次所得的余数都多乘了,2,1,,在求得小数点后的,n,位商后,相当于多乘了,2,n,,所以,正确的余数应为,2,-n.,R,n,。,4,4,/12,例:,X,0.1011,,,Y,0.1101,,计算,X,Y,的商和余数。,R,为负,商上,0,00.1011,+-|Y|,补,11.0011,11.1110,+|Y|,补,00.1101,1,00.1011,左移,1,位,01.0110,+-|Y|,补,11.0011,1,00.1001,左移,1,位,01.0010,+-|Y|,补,11.0011,1,00.0101,解:,|X|,原,00.1011,,,|Y|,补,00.1101,,,-|Y|,补,11.0011,恢复余数,R,为正,商上,1,R,为正,商上,1,R,为负,商上,0,左移,1,位,00.1010,+-|Y|,补,11.0011,11.1101,+|Y|,补,00.1101,1,00.1010,左移,1,位,01.0100,+-|Y|,补,11.0011,1,00.0111,恢复余数,R,为正,商上,1,0 0,0,商,=0.1101,余数,=0.01112,-4,0.1101,5,5,/12,练习:,X,0.1001,,,Y,0.1011,,计算,X,Y,的商和余数。,R,为负,商上,0,0.1011 00.1001,+-|Y|,补,11.0101,11.1110,+|Y|,补,00.1011,1,00.1001,左移,1,位,01.0010,+-|Y|,补,11.0101,1,00.0111,左移,1,位,00.1110,+-|Y|,补,11.0101,1,00.0011,解:,|X|,原,00.1001,,,|Y|,补,00.1011,,,-|Y|,补,11.0101,恢复余数,R,为正,商上,1,R,为正,商上,1,R,为负,商上,0,左移,1,位,00.0110,+-|Y|,补,11.0101,11.1101,+|Y|,补,00.1011,1,00.0110,左移,1,位,00.1100,+-|Y|,补,11.0101,1,00.0001,恢复余数,R,为正,商上,1,0 1,1,商,=,0.1101,余数,=0.00012,-4,0.1101,6,6,/12,二、原码不恢复余数法(加减交替法),恢复余数法的缺点是:,当某一次,-Y,的差值为,负时,要多一次,+Y,恢复余数的操作,降低了,执行速度,又使控制线路变得复杂,因此在,计算机中很少采用。,加减交替法是对恢复余数除法的一种修正。,当某次求得的差值,(,余数,R,i,),为负时,不恢复,,而是继续求下一位商,并在求商的同时暗中,恢复余数。,7,7,/12,运算规则:,本次余数,R,i,为正时,商上,1,,余数左移一位,,下一步减除数求得新余数,R,i+1,;,本次余数,R,i,为负时,商上,0,,余数左移一位,,下一步加除数求得新余数,R,i+1,。,R,i+1,2,(,R,i,|Y|,),|Y|,2R,i,|Y|,但若最后一次上商为,0,,而又需得到正确余数,,则在这最后一次仍需,|Y|,恢复余数。,8,8,/12,例:,X,0.1001,,,Y,0.1011,,计算,X,Y,的商和余数。,R,为负,商上,0,0.1011 00.1001,+-|Y|,补,11.0101,11.1110,左移,1,位,11.1100,+|Y|,补,00.1011,1,00.0111,左移,1,位,00.1110,+-|Y|,补,11.0101,1,00.0011,解:,|X|,原,00.1001,,,|Y|,补,00.1011,,,-|Y|,补,11.0101,R,为正,商上,1,R,为正,商上,1,R,为负,商上,0,左移,1,位,00.0110,+-|Y|,补,11.0101,11.1011,左移,1,位,11.0110,+|Y|,补,00.1011,1,00.0001,R,为正,商上,1,0 1,1,商,=,0.1101,余数,=0.00012,-4,0.1101,9,9,/12,练习:,X,0.1011,,,Y,0.1101,,计算,X,Y,的商和余数。,R,为负,商上,0,00.1011,+-|Y|,补,11.0011,11.1110,左移,1,位,11.1100,+|Y|,补,00.1101,1,00.1001,左移,1,位,01.0010,+-|Y|,补,11.0011,1,00.0101,解:,|X|,原,00.1011,,,|Y|,补,00.1101,,,-|Y|,补,11.0011,R,为正,商上,1,R,为正,商上,1,R,为负,商上,0,左移,1,位,00.1010,+-|Y|,补,11.0011,11.1101,左移,1,位,11.1010,+|Y|,补,00.1101,1,00.0111,R,为正,商上,1,0 1,1,商,=,0.1101,余数,=0.01112,-4,0.1101,10,10,/12,练习:,X,0.1011,,,Y,0.1101,,计算,X,Y,的商和余数。,R,为负,商上,0,00.1011,+-|Y|,补,11.0011,11.1110,左移,1,位,11.1100,+|Y|,补,00.1101,1,00.1001,左移,1,位,01.0010,+-|Y|,补,11.0011,1,00.0101,解:,|X|,原,00.1011,,,|Y|,补,00.1101,,,-|Y|,补,11.0011,R,为正,商上,1,R,为正,商上,1,R,为负,商上,0,左移,1,位,00.1010,+-|Y|,补,11.0011,11.1101,左移,1,位,11.1010,+|Y|,补,00.1101,1,00.0111,R,为正,商上,1,1 0,1,商,=,0.1101,余数,=,0.01112,-4,0.1101,11,11,/12,注意:,对定点小数除法,约定被除数要小于除数,防止溢出。,商的符号为相除两数的符号的,半加和,(即,异或,)。,n,位被除数与除数(不含符号位)相除时,商取,n+1,位(其中第一位是占符号位的),共左移,n,次。,12,12,/12,
展开阅读全文