ALU simulator

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 20
Reputation: kyosuke0 is an unknown quantity at this point 
Solved Threads: 0
kyosuke0 kyosuke0 is offline Offline
Newbie Poster

ALU simulator

 
0
  #1
Apr 11th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: ALU simulator

 
1
  #2
Apr 11th, 2009
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:
  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
"Technological progress is like an axe in the hands of a pathological criminal."

All my posts may be freely redistributed under the terms of the MIT license.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum


Views: 371 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC