943,891 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 5977
  • C# RSS
Apr 28th, 2008
0

Convert C# data types to c++ data types

Expand Post »
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sidharthrshah is offline Offline
3 posts
since Apr 2008
Apr 28th, 2008
0

Re: Convert C# data types to c++ data types

C# has byte and sbyte types depending on if you care about the sign or not.
Reputation Points: 14
Solved Threads: 5
Newbie Poster
$dunk$ is offline Offline
23 posts
since Mar 2008
May 4th, 2008
0

Re: Convert C# data types to c++ data types

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
Reputation Points: 40
Solved Threads: 12
Junior Poster
ChaseVoid is offline Offline
116 posts
since Aug 2007
May 8th, 2008
0

Re: Convert C# data types to c++ data types

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":

C# Syntax (Toggle Plain Text)
  1. using System;
  2.  
  3. namespace Unicode_test
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. byte myByte = 0x48; // 'H' in ASCII, single byte
  10. char myChar = Convert.ToChar(myByte); // should still be 'H"
  11. Console.WriteLine(myChar);
  12. Console.ReadLine();
  13. }
  14. }
  15. }
Team Colleague
Reputation Points: 186
Solved Threads: 147
Cookie... That's it
alc6379 is offline Offline
2,519 posts
since Dec 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: C# - Access - connection
Next Thread in C# Forum Timeline: error while connecting to a database on a different computer





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC