943,565 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1020
  • C++ RSS
Apr 11th, 2009
0

ALU simulator

Expand Post »
hi, i am trying to write a simulation for a very simple ALU and am having trouble with the AND/OR operations. I want to AND/OR integers bit wise with the two integers being passed to a function in hex form and the result returned in hex form so :

int ANDoperation(0x0011, 0x0101)

would return: 0x0001.

iv tried to turn the int's into strings, compare them, then convert the result to int and return that but was having problems with that.

any help is appreciated
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kyosuke0 is offline Offline
20 posts
since Sep 2008
Apr 11th, 2009
1

Re: ALU simulator

Make a function that takes 2 integers as parameters, and returns an integer.

You can print the result in hexadecimal form with the std::hex mode:
C++ Syntax (Toggle Plain Text)
  1. num = ANDoperation(0x0011, 0x0101);
  2. std::cout << "0x" << std::hex << num;
Last edited by John A; Apr 12th, 2009 at 1:09 am. Reason: changed my solution to C++ :o
Team Colleague
Reputation Points: 2240
Solved Threads: 338
Vampirical Lurker
John A is offline Offline
5,055 posts
since Apr 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Weird strtok() problem
Next Thread in C++ Forum Timeline: MSXML4 with c++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC