| | |
Convert C# data types to c++ data types
Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
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
Views: 4055 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access algorithm array barchart bitmap box button buttons c# chat check checkbox class client code color combobox control conversion csharp custom database datagridview dataset datetime degrees draganddrop drawing encryption enum excel file files form format forms ftp function gcd gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox post prime programming radians regex remote remoting resource 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






