Thread: Need help with this code please

  1. #1
    Registered User
    Join Date
    Sep 2018

    Need help with this code please

    unsigned int myAdd(unsigned int p, unsigned int q){
        unsigned int mySum;
       * loop 32 times
       * add a pair of bits from p and q, and the previous carry bit
       * record the sum bit in the corresponding bit in mySum
       * the first carry bit is zero
       * the last carry bit is discarded, assuming no overflow
    int main(){
        unsigned int p, q, mySum,i;
        printf("Enter the 1st integer:\n");
        printf("Enter the second integer:\n");
        return 0;
    I need help how to write myAdd functions this is as far I've gone, I know I have to take MSB of both p and q and then call a fullAdder(msb_p, msb_q), and then shift p and q right. and repeat the loop 32 times but I can't put it into code I'm so confused?
    Please, someone, help thanks in advance.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    For two single bits a and b

    sum = a ^ b;
    carry = a & b;

    Have you searched google for "bitwise addition", there's plenty of things to look at.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-19-2012, 01:58 PM
  2. Replies: 14
    Last Post: 04-01-2008, 02:23 AM
  3. producing c/c++ code from flowcharts,pseudo code , algorithims
    By rohit83.ken in forum C++ Programming
    Replies: 3
    Last Post: 02-20-2008, 07:09 AM
  4. Having trouble translating psudeo-code to real-code.
    By Lithorien in forum C++ Programming
    Replies: 13
    Last Post: 10-05-2004, 07:51 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM

Tags for this Thread