• Articles
  • Auxiliarry Carry & Parity Detector
Published by
Jun 6, 2014

Auxiliarry Carry & Parity Detector

Score: 3.4/5 (35 votes)
*****
This program is useful to check if two numbers can generate an Auxiliary carry or not upon addition. This task can be cumbersome because C/C++ like programming languages although perform in binary in Machine level but their abstraction on binary level & operation on one or more than one variables on binary level to determine the properties of those numbers is not possible.

The above mentioned program can be very useful in engineering the idea to perform on the binary level in High level programming languages like C/C++. Here it is also mandatory to mention that this program is not compatible in C but the basic algorithm & implementation technique can remain same.

This is helpful for mostly those people who are interested in embedded programming or embedded software developing like me but it can still provide the idea/technique to work on the binary level. I created this program for my design of an Emulator for micro-controllers which is able to interpret between hex file & assembly source code to mimic the hardware operation on software level.

The main source code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

#include <iostream>
#include <bitset>
#include <string>
#include <sstream>
using namespace std;
bool AC;
bool P;
string dec2bin(int Decimal_Value){
	ostringstream os;
	os<<bitset<8>(Decimal_Value);
	return os.str();
}
void AC_Flag_Update(unsigned char a, unsigned char b){
	string s1 = dec2bin((int)a);
	string s2 = dec2bin((int)b);
	if ( s1.substr(4,1) == "1" && s2.substr(4,1) == "1" )
		AC = true ;
	else if ( s1.substr(4,1) == "0" && s2.substr(4,1) == "0" )
		AC = false;
	else
		AC_Flag_Update(a<<1 , b<<1);

}
void P_Flag_Update(unsigned char a){
	P = false;
	string s = dec2bin((int)a);
	for ( int i = 0; i < s.size(); i++ ){
		if( s.substr(i,1) == "1" )
			P =!P;
	}
}
int main()
{

	unsigned char c = 0x1a;
	unsigned char d = 0x06;
        AC_Flag_Update(c,d);
	P_Flag_Update(d);
	if(AC)
		cout<<"AC is present"<<endl;
	else
		cout<<"NO AC is present"<<endl;
	if(P)
		cout<<"P is SET"<<endl;
	else
		cout<<"P is CLEAR"<<endl;
}


And the Makefile:

1
2
3
4
5
6
7
8
9
10
11

TARGET= main
CC= g++ -std=c++11

all:
	$(CC) -Os -o $(TARGET) $(TARGET).cpp
run: $(TARGET)
	./$(TARGET)
clean:
	rm -f *~ $(TARGET)



AC is present
P is CLEAR
  • <nobr id="pwjBlLZ"><bdo id="pwjBlLZ"></bdo></nobr>
  • <bdo id="pwjBlLZ"><delect id="pwjBlLZ"></delect></bdo>
  • <bdo id="pwjBlLZ"><delect id="pwjBlLZ"></delect></bdo>
  • <dfn id="pwjBlLZ"></dfn>
  • <dfn id="pwjBlLZ"><delect id="pwjBlLZ"></delect></dfn>
  • <bdo id="pwjBlLZ"></bdo>
  • <bdo id="pwjBlLZ"><delect id="pwjBlLZ"></delect></bdo><dfn id="pwjBlLZ"><delect id="pwjBlLZ"><strike id="pwjBlLZ"></strike></delect></dfn><bdo id="pwjBlLZ"></bdo>
  • <bdo id="pwjBlLZ"></bdo><dfn id="pwjBlLZ"></dfn>
  • <dfn id="pwjBlLZ"></dfn>
  • <dfn id="pwjBlLZ"><delect id="pwjBlLZ"></delect></dfn>
  • <bdo id="pwjBlLZ"></bdo>
  • <dfn id="pwjBlLZ"></dfn>
  • <bdo id="pwjBlLZ"><delect id="pwjBlLZ"></delect></bdo>
  • 6478461606 2018-02-24
  • 4985791605 2018-02-24
  • 5637141604 2018-02-24
  • 282181603 2018-02-24
  • 6217941602 2018-02-24
  • 5076141601 2018-02-24
  • 714281600 2018-02-24
  • 6607141599 2018-02-24
  • 949041598 2018-02-24
  • 6809961597 2018-02-24
  • 671871596 2018-02-24
  • 7107821595 2018-02-24
  • 9407391594 2018-02-24
  • 6234261593 2018-02-24
  • 1793521592 2018-02-23
  • 2864591591 2018-02-23
  • 6167231590 2018-02-23
  • 3669201589 2018-02-23
  • 7946381588 2018-02-23
  • 8957701587 2018-02-23