| | |
Convert C# data types to c++ data types
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2008
Posts: 3
Reputation:
Solved Threads: 0
Hi,
I have a legacy application in vc++ 6.0 which communicates to a server. The server follows c++ data types. I want to convert my legacy application to c#. Now I am facing some conversion issues. The server accepts data in binary format. But when I declare a char data type in C# it takes 2 bytes, whereas char data type in c++ takes 1 byte. How do I convert the char in c# so that it is 1 byte.
I have a legacy application in vc++ 6.0 which communicates to a server. The server follows c++ data types. I want to convert my legacy application to c#. Now I am facing some conversion issues. The server accepts data in binary format. But when I declare a char data type in C# it takes 2 bytes, whereas char data type in c++ takes 1 byte. How do I convert the char in c# so that it is 1 byte.
If you want you can change the size of the char to 1 byte too.
I don't really know how, but some detail might be in the specification or MSDN
this might help http://msdn.microsoft.com/en-us/libr...ar(VS.80).aspx
I don't really know how, but some detail might be in the specification or MSDN
this might help http://msdn.microsoft.com/en-us/libr...ar(VS.80).aspx
Char is 2 byte in .NET because that is how big a Unicode character is. The best thing to do is take the value in as a byte datatype and use the Convert.ToChar() method on that input value.
I just tried it with this code, and you'll see it produces an "H":
I just tried it with this code, and you'll see it produces an "H":
C# Syntax (Toggle Plain Text)
using System; namespace Unicode_test { class Program { static void Main(string[] args) { byte myByte = 0x48; // 'H' in ASCII, single byte char myChar = Convert.ToChar(myByte); // should still be 'H" Console.WriteLine(myChar); Console.ReadLine(); } } }
Alex Cavnar, aka alc6379
![]() |
Similar Threads
- How to convert a string to ASCII ? (C++)
- Pointers (archived tutorial) (C++)
- Several issues - arrays, data types, etc. (C++)
- Please help me to convert a simple C++ program into an object-oriented one. (C++)
- Storing Data from different file formats to a Database (VB.NET)
- Need help with Binary files and data types in VB6 (Visual Basic 4 / 5 / 6)
- Pls help with C code. Evaluating data types. (C)
- adding totals in listboxes (Visual Basic 4 / 5 / 6)
Other Threads in the C# Forum
- Previous Thread: C# - Access - connection
- Next Thread: error while connecting to a database on a different computer
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format formatting forms function gdi+ httpwebrequest image index input install java label list listbox listener mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






