Convert C# data types to c++ data types

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2008
Posts: 3
Reputation: sidharthrshah is an unknown quantity at this point 
Solved Threads: 0
sidharthrshah sidharthrshah is offline Offline
Newbie Poster

Convert C# data types to c++ data types

 
0
  #1
Apr 28th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 23
Reputation: $dunk$ is an unknown quantity at this point 
Solved Threads: 5
$dunk$ $dunk$ is offline Offline
Newbie Poster

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

 
0
  #2
Apr 28th, 2008
C# has byte and sbyte types depending on if you care about the sign or not.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 111
Reputation: ChaseVoid is an unknown quantity at this point 
Solved Threads: 12
ChaseVoid's Avatar
ChaseVoid ChaseVoid is offline Offline
Junior Poster

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

 
0
  #3
May 4th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2003
Posts: 2,414
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Solved Threads: 123
Team Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

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

 
0
  #4
May 8th, 2008
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":

  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. }
Alex Cavnar, aka alc6379
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC