forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Parity Check (odd/even)

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Art



Joined: 09 Nov 2005
Posts: 647

PostPosted: Wed Aug 16, 2006 2:25 pm    Post subject: Parity Check (odd/even) Reply with quote

Hi,
I've run into trouble with an encryption routine I'm trying to clone.
What is the quickest and easiest syntax in C for checking if a byte value
is odd or even?
I tried searching on Google, but mention "Parity" and it's all about error checking.
Thanx, Art.
Back to top
View user's profile Send private message
groepaz



Joined: 01 Sep 2005
Posts: 305

PostPosted: Wed Aug 16, 2006 3:01 pm    Post subject: Reply with quote

if(value&1){ /* odd */ }else{ /* even */}
_________________
http://www.hitmen-console.org
http://hitmen.c02.at/files/yapspd/
Back to top
View user's profile Send private message Visit poster's website
Art



Joined: 09 Nov 2005
Posts: 647

PostPosted: Wed Aug 16, 2006 3:35 pm    Post subject: Reply with quote

Thanx groepaz :)

Is that checking the LSB?
why is bit0 called bit 1?
I guess it all depends on what the "&" is if it's an and I might learn something here..
Back to top
View user's profile Send private message
groepaz



Joined: 01 Sep 2005
Posts: 305

PostPosted: Wed Aug 16, 2006 3:59 pm    Post subject: Reply with quote

yes yes and yes :=) & is bitwise AND, so this masks the LSB (which ofcourse is bit0, not bit1).
_________________
http://www.hitmen-console.org
http://hitmen.c02.at/files/yapspd/
Back to top
View user's profile Send private message Visit poster's website
Samstag



Joined: 24 Nov 2005
Posts: 5

PostPosted: Wed Aug 16, 2006 9:15 pm    Post subject: Reply with quote

groepaz wrote:
if(value&1){ /* odd */ }else{ /* even */}


That's not a parity check, though. You'd want something more like:
Code:
byte parity = 0;
for(i = 0; i < 8; i++)
{
    if(value & 1)
        parity = !parity;    // toggle parity status
    value = value >> 1;  // rotate bits right
}


Untested.
Back to top
View user's profile Send private message
groepaz



Joined: 01 Sep 2005
Posts: 305

PostPosted: Wed Aug 16, 2006 9:25 pm    Post subject: Reply with quote

well the original question wasnt about parity, but "What is the quickest and easiest syntax in C for checking if a byte value
is odd or even?" :=)
_________________
http://www.hitmen-console.org
http://hitmen.c02.at/files/yapspd/
Back to top
View user's profile Send private message Visit poster's website
Samstag



Joined: 24 Nov 2005
Posts: 5

PostPosted: Wed Aug 16, 2006 9:32 pm    Post subject: Reply with quote

Ah, well that's certainly true :)
Back to top
View user's profile Send private message
Art



Joined: 09 Nov 2005
Posts: 647

PostPosted: Thu Aug 17, 2006 6:55 am    Post subject: Reply with quote

That's what I meant.
One of the web definitions for parity:
"The quality of being either odd or even"
Back to top
View user's profile Send private message
siberianstar



Joined: 22 Jun 2006
Posts: 70

PostPosted: Thu Aug 17, 2006 7:52 am    Post subject: Reply with quote

"Parity check" in informatic language is used to define the algorithm to check data errors on trasmission between pc and serial ports.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group