dnhirapara2104

Booth Algo

Apr 23rd, 2021
509
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4.     int x, y;
  5.     cin>>x>>y;
  6.     int m=y;
  7.     int a=0;
  8.     int s=32;
  9.     int qn=0;
  10.     int qn1=0;
  11.     int ans=1;
  12.     for(int i=0; i<30; i++)
  13.     {  
  14.         ans=ans<<1;
  15.         ans=ans|1;
  16.     }
  17.     //cout<<ans<<endl;
  18.     while(s){
  19.         qn=m&1;
  20.         if(qn==1 && qn1==0){
  21.             a=a-x;
  22.         }else if(qn==0 && qn1==1){
  23.             a=a+x;
  24.         }
  25.         int temp=a&1;
  26.         temp=(temp<<31);
  27.         qn1=m&1;
  28.         a=a>>1;
  29.         m=m>>1;
  30.         m=m&ans;
  31.         m=m|temp;
  32.         s--;
  33.         cout<<a<<" "<<m<<endl;
  34.     }
  35.     //int finAns =
  36.     long int acc=a;
  37.     long int finAns=(acc<<31)|m;
  38.     cout<<m<<" "<<finAns<<endl;
  39. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×