Uint ----- byte [] ----- char [] ----- string
Some types of mutual conversion are often required for some interoperability. For example, when using C # To access WIN32API, you often need to input the DWORD parameter to the API: the data represented by the uint value may need to be displayed as characters in actual application, but the relationship between C # APIs cannot be compared with that of C ++, therefore, it is necessary to convert some data types in C,
Some simple conversion operations are pasted below to facilitate memory
Uint ---> byte []
Byte [] bpara= System. bitconverter. getbytes (uint upara );
Byte [] ---> uint
Uint upara = system. bitconverter. touint32 (bpara );
Byte ---> char
System. Convert. tochar (bpara );
Char ---> byte
System. Convert. tobyte (cpara );
Byte [] ---> char []
(1) Char [] cpara = system. Text. encoding. Default. getchars (bpara); (1)
(2) Char [] cpara = new char [bpara. Length];
For (INT I = 0; I <bpara. length; I ++) {char [I] = system. Convert. tochar (bpara [I]);}
(3)Char [] cpara =New asciiencoding (). getchars (bpara );
Char [] ---> byte []
(1)Byte [] bpara = system. Text. encoding. Default. getbytes (cpara );
(2)Byte [] bpara = New asciiencoding (). getbytes (cpara );
Char [] ---> string
String spara = new string (cpara );
String --- char []
Char [] cpara = spara. tochararray ()
Uint ----> char []
(1) uint --> byte [];
(2) byte [] --> char [];
Uint ---> string
(1) uint --> byte [];
(2) byte [] --> char [];
(3) Char [] --> string;
Byte [] ---> string
(1). byte [] --> char [];
(2). Char [] --> string;
(3) New asciiencoding (). getstring (bprar );
Char [] ---> uint
(1). Char [] --> byte [];
(2). byte [] --> uint;
String ---> byte []
Bpara = system. Text. encoding. Default. getbytes (spara)
String ---> uint
(1) string --> byte [];
(2) byte [] --> uint;
Note that when interacting with APIs using uint characters, you must pay attention to the character sequence, which involves the issue of API high/low data, that is, the data obtained from dowrd In the API is usually in reverse order in the C # representation, therefore, when getting or passing strings in C #, you must pay attention to reverse processing before conversion to uint for API use. You have the opportunity to summarize and paste it.