dekoay
asked on
What does this mean in this variable ?
I saw in a code written by a programmer... but I don't know what it means. Hopefully there are some experts could tell me...
The source is as belows...
int bits = (c &0xf0)>>4;
the other one is as below...
c = (char)(~c&0xff);
The source is as belows...
int bits = (c &0xf0)>>4;
the other one is as below...
c = (char)(~c&0xff);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
dekoay:
I may have gone in too much detail in my answer, but I speak from personal experience in that my misunderstanding in how the compiler handled your exact question bit me hard. I spent over 2 days trying to figure out a problem on how come a character ANDed with a number wasn't getting the results I expected. ONLY until I analyzed the assembly code did I realize that ANDing a character with a hex value meant the character was converted to a 4-byte value.
Merry X'Mas,
Glenn
I may have gone in too much detail in my answer, but I speak from personal experience in that my misunderstanding in how the compiler handled your exact question bit me hard. I spent over 2 days trying to figure out a problem on how come a character ANDed with a number wasn't getting the results I expected. ONLY until I analyzed the assembly code did I realize that ANDing a character with a hex value meant the character was converted to a 4-byte value.
Merry X'Mas,
Glenn
ASKER
Hi Glen
Thanks for replying... however I still trying hard to figure out why the programmer put in such a way. May be it is due to the messaages send by the host via winsock is in compressed form.. may be that part is doing the decompressed mode.. I guess...
Merry Xmas to you too.
Thanks for replying... however I still trying hard to figure out why the programmer put in such a way. May be it is due to the messaages send by the host via winsock is in compressed form.. may be that part is doing the decompressed mode.. I guess...
Merry Xmas to you too.
Hi dekoay:
I can't even guess about what the programmer was really doing.
I will say this, there does seem to be a prevalent technique of "flipping" the bits (as the programmer has done with ~c). Somehow the flipping is related to security and just plain 'ol double checking the data received.
I say security in the naive view that if I have a character 'a', for example, if I flip the bits in 'a' then I get something bogus. As long as the sender and receiver know each is to suppose to flip the bits then they can communicate. The person who doesn't know the protocol, gets garbage.
Glenn
I can't even guess about what the programmer was really doing.
I will say this, there does seem to be a prevalent technique of "flipping" the bits (as the programmer has done with ~c). Somehow the flipping is related to security and just plain 'ol double checking the data received.
I say security in the naive view that if I have a character 'a', for example, if I flip the bits in 'a' then I get something bogus. As long as the sender and receiver know each is to suppose to flip the bits then they can communicate. The person who doesn't know the protocol, gets garbage.
Glenn
Glenn