parities and error checking

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
User avatar
xDDunce
Member
Member
Posts: 173
Joined: Tue Aug 12, 2008 4:04 pm
Contact:

parities and error checking

Post by xDDunce »

ok, so in my computing class at college, we have just started doing binary and hex etc. im way ahead of my class :lol: although we have just moved onto parities and error checking when sending messages within a computer but what i was wondering was: Are parities done automaticly by the CPU or should they be built-in to the kernel to ensure all messages are correct?

I am also interested in if anyone knows how to to find if there is an error with the parity bits? all we have touched on is error checking when the error is in the actual data rather than the parities, mainly because there is a higher possibility of that to get an error.

hope this all makes sense. if not i can explain. it isn't difficult really.

Thanks in advance,

James.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: parities and error checking

Post by Combuster »

Are parities done automaticly by the CPU or should they be built-in to the kernel to ensure all messages are correct?
Within a computer, signals are stable enough not to get corrupted in any way (imagine your code randomly changing!) However media external to the computer may not necessarily be. CDs can be scratched, floppies dislike magnets, network cables can pick up noise. What you have to do about these things depends on how they work. Some may not give you corrupt data at all, some will check and correct the data for you, and only for the remaining set will you have to check the data's integrity yourself.
I am also interested in if anyone knows how to to find if there is an error with the parity bits? all we have touched on is error checking when the error is in the actual data rather than the parities, mainly because there is a higher possibility of that to get an error.
The problem with such scheme is that with one parity unit you can never detect the location of the error - you can always change exactly one of the units in the set at will to make the set appear correct again.
Also, if you know the location of the error, you can attempt to fix it as well, making anything of that sort no longer error checking, but rather error correction.

Try the following scheme with parity bits (one of the simplest forms of error correction):

Code: Select all

0 1 1 0 1 1 0 0 | 0
1 0 1 0 1 0 0 1 | 0
1 1 1 0 0 0 1 1 | 1
----------------+--
0 0 1 0 0 1 1 0 | 1 
Now if there's exactly one bit off, you can locate it:

Code: Select all

0 1 1 0 1 1 0 0 | 0 <- ok
1 0 1 0 1 0 0 1 | 0 <- ok
1 1 1 0 0 0 1 1 | 1 <- ok
----------------+--
0 0 1 0 1 1 1 0 | 1 <- wrong
v v v v X v v v   v
By checking each row and column, you can detect which lines are wrong, and therefore, where the error must lie. In this case, one of the parity bits was accidentally set:

Code: Select all

        |       |   <- ok
        |       |   <- ok
        v       |   <- ok
------>(1)<-----|-- <- wrong
v v v v X v v v   v
Note that when there are too many errors, you can not recover, or even find the wrong answer:

Code: Select all

0 1 1 0 1 1 0 0 | 0 <- ok
1 0 1 0 1 0 0 1 | 0 <- ok
1 1 1 1!1!0 1 1 | 1 <- ok
----------------+--
0 0 1 1!0 1 1 0 | 1 <- wrong
v v v v X v v v   v
Of course, there are many alternative, more complex, and more effective algorithms around.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: parities and error checking

Post by bewing »

And if you really do want to check parities, the x86 cpu automatically calculates the parity of the result of every calculation. So you can test parity at any time you want.
Combuster wrote: Within a computer, signals are stable enough not to get corrupted in any way (imagine your code randomly changing!)
Of course, that is a slight overgeneralization. One reason that your computer crashes every 8 months is precisely because an unfriendly gamma ray trashed an important bit in a program.
User avatar
xDDunce
Member
Member
Posts: 173
Joined: Tue Aug 12, 2008 4:04 pm
Contact:

Re: parities and error checking

Post by xDDunce »

so, in conclusion, it would just be time consuming to run the checks everytime i send a signal anyway. and when it comes to making multimedia drivers, it would be worth my while to implement it?

thanks for the detailed reply combuster, that cleared things up alot.

and to bewing, thanks for the extra knowledge. i never knew gamma rays could do that! :lol:

thanks again,

James.
Post Reply