Click here to Skip to main content
15,916,693 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to convert Bytecode to Char in c# Win. Form
Example
if the byte code is 1111111111111101 then answer should come

any piece of code snippet is appreciated


Thanks in advance
Posted
Updated 24-Nov-14 23:48pm
v2

1 solution

Try just casting it:
C#
byte b = Convert.ToByte("01100001", 2);
char c = (char)b;
Console.WriteLine(c);
(You can't enter binary constants in C#, just hex or decimal)
 
Share this answer
 
Comments
agent_kruger 25-Nov-14 5:48am    
sir, i am having the problem with 16 digit byte code which is "1111111111111101" and its value is "�". can you help me with this?
OriginalGriff 25-Nov-14 6:32am    
You don't get 16 bit bytes: they are a fixed size of 8 bits.
So check exactly what you have and where you got it from, and post the code - I think you have something a bit confused...
agent_kruger 25-Nov-14 7:12am    
no sir please see that many characters does return 16 bit. if you don't believe me then try changing value of "(char)65533" to byte code you will find out on your own.
OriginalGriff 25-Nov-14 7:27am    
That's because char is a 16 bit datatype: byte is 8 bit.
Depending on what you are doing, and the source of the byte data you will have to treat it very differently.

The size of an actual character depends on the system: for modern Windows it's Unicode - 16 bits with a variable character size.
For a lot of systems (and some SQL datatypes) it's ASCII - 8 bits, fixed.

You can't just go "it's this" and assume it will work.

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