mohi@608
Member level 4
i am trying to use bit set in one of my code but when i am using to_ulong command i am unable to get a desired result...
the code is given below......
pls check....
the code is given below......
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 #include <iostream> #include <string> #include <bitset> using namespace std; class add { int r0,r1; public: int add_opcode(bitset<8> r0,bitset<8> r1); }; int add::add_opcode(bitset<8> r0,bitset<8> r1) { bitset<1> c,z,v; bitset<9> sum; int a,b; a=r0.to_ulong(); b=r1.to_ulong(); cout<<a<<"\n"<<b<<"\n"; sum=a+b; //r0=sum; cout<<r0<<"\n"; if(sum[8]==1) cout<<"c=1"<<"\n"<<" v=1"<<" \n"; else cout<<"c=0 "<<"\n"<<" v=0"<<"\n"; if(sum==0) cout<<" z="<<0<<"\n"; else cout<<" z="<<1<<"\n"; cout<<"sum= "<<sum<<endl; return 0; } int main() { add d1,d2,d3,d4; d1.add_opcode(00001111,00000000); d2.add_opcode(10001000,11111111); d3.add_opcode(0000,00000); d4.add_opcode(11111111,11111111); }
pls check....
Last edited by a moderator: