Program 2
Program 2
(Sem II)
Practical No.2
Program :
#include<stdio.h>
#include<conio.h>
void disp_binary(int x)
{
int masks[16]={0x8000,0x4000,0x2000,0x1000,
0x0800,0x0400,0x0200,0x0100,
int i;
for(i=0;i<16;i++)
if((x & masks[i])==0)
printf("0");
else
printf("1");
}
void main()
0x0080,0x0040,0x0020,0x0010,
0x0008,0x0004,0x0002,0x0001};
{
Computer Programming Lab - F.Y. B. Tech. (Sem II)
int acq,m,q_1,i,q_0;
printf("\nEnter multiplicant(-128 to 127): ");
scanf("%d",&m);
printf("Multiplicant in Binary: ");
disp_binary(m);
printf("\nEnter multiplier(-128 to 127): ");
scanf("%d",&acq);
printf("Multiplier in Binary: ");
disp_binary(acq);
acq=(acq & 0x00ff);
q_1=0;
printf("\n");
disp_binary(acq);
printf("%d",q_1);
printf("Booths Cycle:\n");
for(i=0;i<8;i++)
{
}
q_0=acq & 0x0001;
if(q_0==1 && q_1==0)
acq=acq - (m<<8);
else
Computer Programming Lab - F.Y. B. Tech. (Sem II)
Output :
Enter multiplicant(-128 to 127): -7
Multiplicant in Binary: 1111111111111001
Enter multiplier(-128 to 127): -3
Multiplier in Binary: 1111111111111101
00000000111111010Booths Cycle:
00000011111111101
Computer Programming Lab - F.Y. B. Tech. (Sem II)
11111110011111110
00000010101111111
00000001010111111
00000000101011111
00000000010101111
00000000001010111
00000000000101011
Product = 21
0000000000010101 --------------------------------
Process exited after 6.64 seconds with return value 49
Press any key to continue . . .