Sunday 15 August 2010

bit manipulation - Bit shifting a character with wrap? C++ -


I have a binary file that will be read in characters; each character has an unknown number (left with wrap) I wanted to be able to read in every character and then wrap the shift on the right (To make the change again and again I feel that I have to know manually, because I have no other way. In a).

So, my current consideration is that I read in one character, make a copy temporary and then use XOR:

  four letters; // will be read in the letters; // will keep a copy of the letter while the file (file; and letter, size) Letter now Letter 00001101 {temp = letter; // temp now keeps the letter 00001101> = 1; / / 1 position Move to the right, the letter now holds 00000110 temporary and the lieutenant;   

It makes sense in my tired head, but it does not work And ... I can not do that, according to the figures, the size of the four is 1 byte, so I thought that I only have to drag it with 8 bits.

Any help will be appreciated.

Note the signature of four. It has been signed on several systems, so your letter> = 1 sign to fill the change.

The rotating integer is usually done as follows letter = ((unsigned char) letter >> 1). (Letter & lt; <7); As Marc comments in the form of

, you can either | You can use or XOR ^ . >

No comments:

Post a Comment