C++ 中byte[] 类型到long类型的转换

最近因为需要写一个ActiveX,需要在C++中有一个对应C#中byte[] 类型到long类型的转换, byte[] 和long类型分别对于C++中的unsign char[] 和long long 类型,这个我一开始的时候犯了个错误,用的是long类型,所以结果一直不对,查了资料后才知道对应C#中long应该是C++中的long long .
   

Type Name Bytes Other Names Range of Values
char1signed char–128 to 127
unsigned char1none0 to 255
long4long int, signed long int–2,147,483,648 to 2,147,483,647
long long8none (but equivalent to __int64)–9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

转换的函数如下:
long long byteToLong(unsigned char b0, unsigned char b1, unsigned char b2, unsigned char b3,unsigned char b4, unsigned char b5, unsigned char b6, unsigned char b7)
{
  unsigned
char aChar[8]= {b0,b1,b2,b3,b4,b5,b6,b7};
  
return *(((long long*)aChar));
}

转载于:https://www.cnblogs.com/yashen/archive/2005/06/23/179640.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值