Accessing Bits
SRLM
Posts: 5,045
Hi
How do you get into the individual bits of a long? I'm working through a protocol that needs a start bit of 0 and a stop bit of 1, along with a parity bit.
Also, is there an easy way to get a bit that tells the odd parity? I was going to use something like a loop and two counters, but I suspect that there must be an easier way.
Thank you.
How do you get into the individual bits of a long? I'm working through a protocol that needs a start bit of 0 and a stop bit of 1, along with a parity bit.
Also, is there an easy way to get a bit that tells the odd parity? I was going to use something like a loop and two counters, but I suspect that there must be an easier way.
Thank you.
Comments
In assembly language, the logical operations put the parity of the result into the carry flag. In Spin there's no easy way. You can write an expression that xor's all the bits of interest together to get the parity. For serial communications, it's not too hard:
char |= (((char >> 6) ^ (char >> 5) ^ (char >> 4) ^ (char >> 3) ^ (char >> 2) ^ (char >> 1) ^ char) << 7) & %10000000
This converts a 7 bit value to 8 bits including odd parity.
Can you give a short lesson how to read/interpret that, please ?!
It looks like what you're doing is shifting bits right, then I get lost with the chevron and amperstand.
Any explanation would be great. Also, I took a more beginer's approach and wrote a good 'ole for-loop.
Looks okay to me. Are there any errors that anybody can spot?