惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Last Watchdog
The Last Watchdog
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
小众软件
小众软件
雷峰网
雷峰网
F
Full Disclosure
B
Blog
Hugging Face - Blog
Hugging Face - Blog
GbyAI
GbyAI
月光博客
月光博客
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
TaoSecurity Blog
TaoSecurity Blog
博客园 - 聂微东
P
Palo Alto Networks Blog
N
Netflix TechBlog - Medium
S
Secure Thoughts
Google Online Security Blog
Google Online Security Blog
P
Privacy & Cybersecurity Law Blog
U
Unit 42
Cloudbric
Cloudbric
Know Your Adversary
Know Your Adversary
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Vercel News
Vercel News
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
N
News and Events Feed by Topic
T
Tailwind CSS Blog
S
Schneier on Security
IT之家
IT之家
P
Proofpoint News Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
Tenable Blog
Google DeepMind News
Google DeepMind News
The GitHub Blog
The GitHub Blog
T
Troy Hunt's Blog
V2EX - 技术
V2EX - 技术
Cyberwarzone
Cyberwarzone
P
Privacy International News Feed
I
InfoQ
MongoDB | Blog
MongoDB | Blog
Project Zero
Project Zero
B
Blog RSS Feed
Help Net Security
Help Net Security
H
Heimdal Security Blog
有赞技术团队
有赞技术团队
The Register - Security
The Register - Security
V
V2EX
C
CXSECURITY Database RSS Feed - CXSecurity.com
J
Java Code Geeks

博客园 - 吴碧宇

NPM私有服务器架设 FOR CentOS 【转】c# 位操作 C#中调用Windows API时的数据类型对应关系 全面理解javascript的caller,callee,call,apply概念[转载] 发几个小的测式软件 用户中心 - 博客园 Vs2010 配置驱动开发环境 美杜杉 主动防御最新版 Asp.net 异步请求 IHttpAsyncHandler [转]COM线程模型-套间 [转]VC使用CRT调试功能来检测内存泄漏 [转]C++深度探索系列:智能指针(Smart Pointer) [一] [转]DirectShow+VS2005配置日记 [转]Windows API 注册表函数 特殊符号表 【转】C++反射机制的实现 ATL 开发 Com 学习笔记 常用数据类型使用转换详解 - 吴碧宇 - 博客园 [转]BSTR、char*和CString short转换
[转]c#中 uint--byte[]--char[]--string相互转换汇总
吴碧宇 · 2009-12-04 · via 博客园 - 吴碧宇
 

uint-----byte[]-----char[]-----string

        在在做一些互操作的时候往往需要一些类型的相互转换,比如用c#访问win32api的时候往往需要向api中传入DWORD参数 即:uint参数这些数值所表示的数据在实际的应用中可能需要以字符的形式显示,但是c#对api的关系无法跟c++相比,所以在c#中进行一些类型数据的转换十分必要了,
    下面将用到的一些简单的转换操作贴上来,方便记忆 
     

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;

    注意在跟api用uint进行字符交互的时候,一定要注意字符顺序,涉及到api中高低位数据的问题,即获取到api中DOWRD的数据在c#表示中往往是反序,所以在c#中获取或者传递字符串时一定要注意反序处理后才能转换成uint给api使用,有机会好好总结一下贴上来。