Advertisement
AntonioVillanueva

OneBitMultiplier UAB MOOC

Mar 7th, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. #define N 7
  7. #define M 7
  8. typedef bitset<8> BYTE;
  9. typedef bitset<1> BIT;
  10.  
  11. struct next_x {BIT next_a ;BIT next_c;};
  12.  
  13. bool OnebitMultiplier (bool a, bool x, bool y ,bool  c , bool next_a ,bool next_c){
  14.  
  15.     next_c = ( a & c ) | ( a & ( x & y)) | (c & (x & y));
  16.     next_a = a ^ (x & y) ^ c;
  17.     return a;
  18. }
  19.  
  20.  
  21.  
  22. int main (){
  23.  
  24.     BYTE X(1);
  25.     BYTE Y(2);
  26.     BYTE acc(0);
  27.     bool carry(false),next_a(false),next_c(false);
  28.  
  29.     size_t i(1),j(1);
  30.    
  31.  
  32.     for (i=1 ; i<= pow (2,N) ; i<<=1){
  33.         for (j=1;j<= pow (2,M);j<<=1){
  34.  
  35.         acc|=OnebitMultiplier( acc [i|j ],X[j],Y[i],& carry, & next_a, & next_c) ;
  36.  
  37.         }
  38.        
  39.     }
  40.    
  41.  cout <<X<< " * "<<Y<< " = "<< acc<<endl;
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement