Manipulate two 8-Bits using Carry?

Discussion in 'C++' started by Bryan Parkoff, Sep 6, 2005.

  1. I break one U_WORD variable into two U_BYTE variables. I prefer to
    manipulate two U_BYTE variables instead of one U_WORD variable using Carry.
    Please look at my example using U_WORD variable below.

    typedef unsigned char U_BYTE;
    typedef unsigned short int U_WORD;

    U_WORD HighLow = 0x00FE;
    HighLow += 0x04;
    U_BYTE Carry = HighLow >> 8;

    It is not what I want to use this above. Please look at my example
    using two U_BYTE variables below.

    typedef unsigned char U_BYTE;

    U_BYTE Low = 0xFE;
    U_BYTE High = 0x00;
    U_BYTE Carry = 0x00;
    U_BYTE Temp = Low;
    Low += 0x04;

    if (Temp <= Low)
    Carry = 0x00;
    else
    {
    Carry = 0x01;
    High += Carry;
    }

    My code above works fine. It is what I am using. It always use
    unsigned when Low increases. If it wraps to 0, it sets Carry to increase
    High. How can I write signed code? It has to tell Low to decrease using
    signed. If it wraps to 0xFF, it sets Carry to decrease High. Low must
    always use "+" to support unsigned and signed. For example below.

    typedef unsigned short int U_WORD;
    typedef signed short int S_WORD;

    U_WORD HighLow = 0x0002;
    HighLow += (S_WORD) 0xFC; // It shows 0xFFFE
    U_BYTE Carry = (HighLow >> 8) & 0x01; // It captures 0xFF to mask 0x01.

    Can you please write two U_BYTE variables using signed in an example
    code?


    Bryan Parkoff
    Bryan Parkoff, Sep 6, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave
    Replies:
    1
    Views:
    316
    Mike Wahler
    Jan 22, 2005
  2. sarahh

    sum of 64 bits using 32 bits cpu

    sarahh, May 13, 2008, in forum: C Programming
    Replies:
    18
    Views:
    526
    Richard Tobin
    May 14, 2008
  3. David

    Carry two values from Radio value...

    David, Oct 21, 2004, in forum: ASP General
    Replies:
    1
    Views:
    126
    Ray Costanzo [MVP]
    Oct 21, 2004
  4. PerlFAQ Server

    FAQ 4.53 How do I manipulate arrays of bits?

    PerlFAQ Server, Feb 10, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    117
    PerlFAQ Server
    Feb 10, 2011
  5. PerlFAQ Server

    FAQ 4.53 How do I manipulate arrays of bits?

    PerlFAQ Server, Mar 24, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    114
    PerlFAQ Server
    Mar 24, 2011
Loading...

Share This Page