Manipulate two 8-Bits using Carry?

B

Bryan Parkoff

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top