Click to See Complete Forum and Search --> : Format string in 7 data bits/ 1 parity bit/ even parity


forandrey
September 5th, 2002, 05:39 PM
Hi guys.

I need to format string in 7 data bits/ 1 parity bit/ even parity.

Many thanks.

Andrey

mikescham
September 5th, 2002, 08:06 PM
Could you explain the what and why of your post. We just had a project at work that used base64 encoding which might be close to what you are trying to do but I don't quite understand what you mean by the parity / even parity thing.

VNT
September 5th, 2002, 09:43 PM
I think he is doing something with Serial port... ?? or something with the protocol / message that's received...

I don't understand either

forandrey
September 5th, 2002, 11:27 PM
Hi guys.

I’m sorry for the first short question.
There is a third party company’s SSL gateway. I can connect to that gateway as an HTTPS server. My task is to connect to that HTTPS server and send request to the server as the body of an HTTP POST transaction. The row binary request must be formatted in 7 data bits/1 bit/even parity (7 data bits/1 bit/even parity I got from the gateway’s documentation).
Any ideas?

Thanks.

Andrey

mikescham
September 6th, 2002, 12:16 AM
OK did some checking. Here is the definition of even parity I found:

The data bits plus the parity bit produce an even number of 1's.

ASCII is an 8 bit encoding but it only uses seven bits leaving the 8th bit open to be used as a parity bit.

You should be able to use the BitConverter class to convert a string to a byte array. You then need to determine the number of 1 bits in each byte and bitwise 'or' the byte with 0x80 or (128 in base 10) if the number of 1 bits is odd or else leave it at 0 if the number of 1 bits is already even. You can probably simplify this a little by using a hash as a cipher. Just make your alphanumeric characters your keys and precalculate the number of 1 bits in each character. Then all you have to do is loop thru each character in your string, use it as a key to your hash, retrieve the value to 'or' with your byte (0x80 when odd, 0 when even -- or do nothing) and dump the result into an output byte array.

There may be some formula to work out the number of 1 bits in a number and greatly simplify the process but I couldn't find any patterns...

Hope this helps!

forandrey
September 6th, 2002, 11:16 AM
Thanks a lot!