Implementing hex flags

Thread Starter

Samantha Groves

Joined Nov 25, 2023
151
Suppose we have a circuit which adds 2 Hex numbers lets say A+F and stores the result in another register.In binary form it is easy to implement the carry,overflow,zero and negative flag however in hex what would be the equivalents.Im using 4 bit registers and I dont have access internaly to the register which means I cannot calculate these flags bit by bit.

Now that I have thought this thru the carry flag is easy to implement because it is very similar to the case of binary but the others are not very well thought out.

Thanks for your help!
 

MrChips

Joined Oct 2, 2009
34,626
Hex and binary are same thing, i.e. they are both four binary bits representing the same thing.

F = 1111 = 2^3 + 2^2 + 2^1 + 2^0
 

Thread Starter

Samantha Groves

Joined Nov 25, 2023
151
Hex and binary are same thing, i.e. they are both four binary bits representing the same thing.

F = 1111 = 2^3 + 2^2 + 2^1 + 2^0
Well yes thats true.But here is my issue.To get the overflow flag of a 4-bit binary adder you need to know the carry and the sum of the MSB and XOR them however now we only have 2 Hex digits(I cannot access bit by bit the register)so which circuitry must I connect the 2 HEX digits to get the overflow flag?
 

MrChips

Joined Oct 2, 2009
34,626
Ignore the fact that you have two hex digits. Treat them as two 4-bit binary values.
value 1 = DCBA
value 2 = dcba

Simply add the two together as DCBA + dcba.
The result is a 5-bit binary value.
 

Papabravo

Joined Feb 24, 2006
22,058
Ignore the fact that you have two hex digits. Treat them as two 4-bit binary values.
value 1 = DCBA
value 2 = dcba

Simply add the two together as DCBA + dcba.
The result is a 5-bit binary value.
Isn't that going to be 16 bits plus a Carry flag.
 

boostbuck

Joined Oct 5, 2017
1,032
Suppose we have a circuit which adds 2 Hex numbers..... .Im using 4 bit registers....
If you adding using 4 bit registers then you are using binary, even if you prefer to interpret the values using hexadecimal symbology.

The addition using hexadecimal would be using 16-value logic rather than 2-value in binary, but it follows the same rules as binary (or any other base for that matter) when dealing with carry and borrow.
 

neonstrobe

Joined May 15, 2009
199
Ignore the fact that you have two hex digits. Treat them as two 4-bit binary values.
value 1 = DCBA
value 2 = dcba

Simply add the two together as DCBA + dcba.
The result is a 5-bit binary value.
Well, is that not the problem? With a 4 bit register, you don't have 5 bits to play with.
Unless some additional logic is added to specifically handle the carry then it may be necessary to check "manually" by testing the two values to be added and generating a third 4 bit number when overflowing.
 

MrChips

Joined Oct 2, 2009
34,626
When you add two 4-bit values, you can expect a carry when the sum is greater than 1111. The carry is the 5th bit.
For example, 1111 + 0001 = 10000.
 

WBahn

Joined Mar 31, 2012
32,702
Well yes thats true.But here is my issue.To get the overflow flag of a 4-bit binary adder you need to know the carry and the sum of the MSB and XOR them however now we only have 2 Hex digits(I cannot access bit by bit the register)so which circuitry must I connect the 2 HEX digits to get the overflow flag?
What, exactly, DO you have access to? Don't say "two hex digits", because that is going to be taken to mean that you have access to a total of eight signals -- four binary signals for each hex digit.
 
Top