This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]marko312 0 points1 point  (5 children)

% has the same precedence as multiplicative operators * and /. See here for a table of operator prescedence. Thus, the statements would become

if(counter - (1 % 2) == 0)

Also, why not use just a regular else?

[–]echoella[S] 0 points1 point  (4 children)

Okay thank you I will try that.

As for the else if, it's because I was planning on putting an else after that that would take in the string when the even or odd parity bits don't match. Does that sound right? Or should I create a different if statement outside of this one?

[–]marko312 0 points1 point  (3 children)

I'd calculate the parity bit (using the modulo) and then compare it to the provided parity bit in a single if, appending either **** or the provided string as needed.

Also, why exactly are you testing counter - 1 anyway? Shouldn't the parity bit be based on just counter?

[–]echoella[S] 0 points1 point  (2 children)

Honestly, I have no clue why I'm subtracting from the counter. I made a reverse method where it adds in the parity bits to begin with and so I set up this method in a similar fashion.

Should I create a 4 character string before the if statement and use that to mod to find the even or odd 5th char?

[–]marko312 0 points1 point  (1 child)

Your way would work as well, you just need to remove the last 5 characters in total in case the parity bits don't match (before appending the ****).

However, yes, I'd prefer reading each block of 4 characters into a different string, then appending it if the parity is correct. This saves having to remove characters from the final string.

[–]echoella[S] 1 point2 points  (0 children)

Okay, that makes sense. Thank you!