I'm confused as to what you mean by XORing a byte, if not bit by bit.
Okay.. here's the question - what's the easist way of making an XOR checksum byte for a string.
I would think some think like this:
Problem - ^ is a bitwise operator and a byte is 8 bits, and we need the result of xoring the bytes indidually not the bits indvidually.Code:int hold; int checksum = string[0]; for(int i=1, i > strlen(string)-1, i++) { hold = checksum; checksum = string[i] ^ hold; }
I figured that Xoring the string and appending my checksum as an int, cast as a char - it should be safe as the int never will be bigger then the byte can hold.
(I have to convert my ints to chars to be able to use them futher on in my system - I'll post the entire code later for you guys to laugh at)
basic idea:
Pack string in HDLC compliant format, send to external unit,
string -> stick - DLE, STX, Adresse of external unit, Control field (will be a bitfield), ID, PAYLOAD (our string), ETX and Checksum. -> HEY HO... off to I/O we go..
I'm confused as to what you mean by XORing a byte, if not bit by bit.
Why not dump the individual chars into a vector? Or make a class for the correct output? Of course, I'm still fuzzy on what you are trying to do...
No problem, I think I got a solution which is much cleaner.
Just need to debug the code a bit.
If your complaint is about using a 16-bit integer to make checksums byte by byte, then don't use an integer. Use another char.
oh no... if had to choose I wouldn't even do it XOR style... I would use a proper CRC16/32 checksum, the assignment requires me to use one char XOR checksum - 8 bits. If I don't do that I'll break protocol and my project group will kill me...If your complaint is about using a 16-bit integer to make checksums byte by byte, then don't use an integer. Use another char.
Well then my suggestion should be fitting.oh no... if had to choose I wouldn't even do it XOR style... I would use a proper CRC16/32 checksum, the assignment requires me to use one char XOR checksum - 8 bits. If I don't do that I'll break protocol and my project group will kill me...
Oh I am using a char, sorry for the mix up.
Well then my suggestion should be fitting.
doh did I just write int in my code ex..... stupid me...
Just a question, ive had some C++ but what do you mean by XORing a byte not bit by bit? How do you XOR a whole byte? Isnt it essentially doing it bit by bit no matter what?
No worries, seems I got the protocol design wrong, my friend corrected it and I'll post his code tomorrow. He's code is much cleaner than mine, but I suspect he had help from our local C++ guru... Which really is cheatingJust a question, ive had some C++ but what do you mean by XORing a byte not bit by bit? How do you XOR a whole byte? Isnt it essentially doing it bit by bit no matter what?(when I do it it's clever...
)
Bookmarks