Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ASCII PARITY Encoder

Status
Not open for further replies.
Hi,
I have to write a program of EVEN 7-bit ASCII parity encoder
the 8 bit use for encoding purposes
have to convert 8th bit to even parity encoder
1st byte is located at RAM
Program out put shouldn't consist more than 10 bits

Have to use ASCII control character EOT
not sure on how to start
Any help will be great
thanks for your help
will be helpful if can suggest what to look for (any particular topic on this) which will help
thanks
 
Last edited:
Start by deciding which processor, language, compiler etc you will use. Then count the number of 1 bits in your 7 bits and make the eight bit 1 if the number of 1 bits is 0,2,4, or 6, otherwise zero.

Mike.
 
Start by deciding which processor, language, compiler etc you will use. Then count the number of 1 bits in your 7 bits and make the eight bit 1 if the number of 1 bits is 0,2,4, or 6, otherwise zero.

Mike.
Thanks for your reply.
Will use SDK 85
 
Seems odd this.... We are talking about 7 bits not 8.... so it can never be even....

The number of bits set to 1 can be even.

Here is an algorithm to count "ones" in a char:

C:
int count_ones(unsigned char x) {
   x = x - ((x >> 1) & 0x55); 
   x = (x & 0x33) + ((x >> 2) & 0x33); 
   x = (x + (x >> 4)) & 0x0F; 
   return x & 0x3F; 
}
 
Last edited:
I cant see how....
Here is an algorithm to count "ones" in a char:

Its not a char if it only has 7 bits... Unless you assume the eighth bit was a zero..

4 ones, 2 ones etc.. as Mike said... But neglecting that eighth bit, an odd number of bits can NEVER have an even parity.

I always assumed that the level of 1's and 0's set the parity, not 0,2,4 6 and 8 1's
 
Program out put shouldn't consist more than 10 bits
:confused: I thought you had an 8-bit data-width (the 8th bit being parity)?

I always assumed that the level of 1's and 0's set the parity, not 0,2,4 6 and 8 1's
According to Wikipedia:
"In case of even parity, the parity bit is set to 1, if the number of ones in a given set of bits (not including the parity bit) is odd, making the number of ones in the entire set of bits (including the parity bit) even. If the number of ones in a given set of bits is already even, it is set to a 0."
 
Last edited:
Definition: Even parity: In asynchronous communications, an error-checking technique that sets an extra bit (called a parity bit) to 1 if the number of 1 bits in a one-byte data item adds up to an even number. The parity bit is set to 0 if the number of 1 bits adds up to an odd number. See odd parity and parity checking.

Ok I concede..

Mike is right... Mr T's also right...
 
I cant see how....

Its not a char if it only has 7 bits... Unless you assume the eighth bit was a zero..

4 ones, 2 ones etc.. as Mike said... But neglecting that eighth bit, an odd number of bits can NEVER have an even parity.

I always assumed that the level of 1's and 0's set the parity, not 0,2,4 6 and 8 1's
the 8 bit is dnt care mode...
Even or Odd wouldn't matter ..so can do it either way...which ever is less complex...:)
 
this is the chart I found on Wikipedia
7 bits of data (count of 1 bits) 8 bits including parity
even odd
0000000 0 00000000 00000001
1010001 3 10100011 10100010
1101001 4 11010010 11010011
1111111 7 11111111 11111110
 
That chart has the most significant bit in the rightmost position. I (and most others) write binary and decimal with the most significant digit (bit) in the leftmost position. So your chart would become,
Code:
Decimal    Binary       bits    Even            Odd
0          0000000	0	00000000	10000000
81         1010001	3	11010001	01010001
105        1101001	4	01101001	11101001
127        1111111	7	11111111	01111111

HTH

Mike.
 
That chart has the most significant bit in the rightmost position. I (and most others) write binary and decimal with the most significant digit (bit) in the leftmost position. So your chart would become,
Code:
Decimal    Binary       bits    Even            Odd
0          0000000	0	00000000	10000000
81         1010001	3	11010001	01010001
105        1101001	4	01101001	11101001
127        1111111	7	11111111	01111111

HTH

Mike.
yeah much better now
thanks
 
so this is the binary number 0111 1111
the 8 bit is zero..in don't care mode.

You have to ask yourself why would you care? If it does not matter then don't care...
 
Why do you write it as zero if it is "don't care"?
 
Status
Not open for further replies.

Latest threads

Back
Top