hello!
I have a char called 'ch',
how can I get it's binary value?
thanks
:wave:
Printable View
hello!
I have a char called 'ch',
how can I get it's binary value?
thanks
:wave:
Here is a link to a short program to do this type of thing..
http://support.microsoft.com/default...b;en-us;109260
It's in VB.NET, but since you know VB 6, there shouldn't be any problems in easily converting it.
Bill
If you mean you want its ASCII or Unicode value then use:If you want to see the binary representation of the integer then you would use:Code:int charCode = Convert.ToInt32(ch);
If you mean something else then it's not clear to me.Code:string binaryCharCode = Convert.ToString(charCode, 2)
Wouldn't the binary representation be base 2 rather than 16 which is Hex?
string binaryCharCode = Convert.ToString(charCode, 2)
I'm sure I don't know what you're talking about. The base IS 2 in my code and always was, no matter what anyone says. :blush: :DQuote:
Originally Posted by RohanWest
You dont know the difference between a char and int? I hope you do now!
I encountered the same Issue. I parse a binary as an integer for a script interpreter. when i do a binary negationi get the 2's complement but with 32 bit because its an integer? how can i convert the integer to a char in base2?Code:~
Because i cant edit my post - dont know why - here is what i do
Code:int intValue = Convert.ToInt32(strToken, 2);
listTokens.Add(new Token(TokenType.Integer, intValue, m_iSourceLine, m_iSourceChar, strSourceLine));
Hello, @dekelc
Please try this code,To convert char to binary:
Input Data : StringToBinary("fluxbytes.com")
I hope above code will be useful for you.Code:public static string StringToBinary(string data)
{
StringBuilder sb = new StringBuilder();
foreach (char c in data.ToCharArray())
{
sb.Append(Convert.ToString(c, 2).PadLeft(8, '0'));
}
return sb.ToString();
}
Thank you.