Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am converting a string to a binary number with the function
C#
BinaryVersionSerialNumber = Convert.ToString(SerialNumber, 2);
This appears to give a binary number which I can put on the form the SerialNumber which is an Int32 (a 32 bit integer I think) I got the conversion to work with a lot of help yesterday from CPallini, However reversing the beast has got me a little confused, I was working on the assumption that X' = (X^Y), would allow you to do X = (X'^Y), but it doesn't seem to. Is my logic wrong or has the conversion to binary broken ?


Glenn (I need more coffee!)

Thanks for the advice, see comments below. The issue I have now is if performing the bitwise operation
C#
Result = PassCode;
          MessageBox.Show(Result.ToString());

          Result = (Result & 0xFFF00000);
          MessageBox.Show(Result.ToString());

Result is cleared from the string giving 0, it would appear that the int32 that is Result
when it is 'and' with the Hex filler gives 0. I am a little confused by this?
Glenn
Posted
Updated 16-May-14 1:23am
v2
Comments
Prasad Khandekar 16-May-14 6:40am    
Hello Glenn,

If I understand correct The code snippet you have shown converts an integer to a binary string and that string you want to convert back to integer right? If answer is yes then you can use Convert.ToInt32(BinaryVersionSerialNumber, 2) to get the original Integer SerialNumber.

Regards,
CPallini 16-May-14 6:42am    
While working with bitwise operations you shouldn't use strings at all.
glennPattonWork3 16-May-14 6:46am    
Ahh, I need to convert the string to an integer then and leave it alone...
CPallini 16-May-14 6:49am    
General pattern:
1. Convert strings coming from GUI to numbers.
2. Always execute bitwise operations on numbers.
3. Convert back operation result numbers to strings in order to use them in the GUI.
glennPattonWork3 16-May-14 6:52am    
I will give that a go, Thanks Glenn

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900