久久久国产精品视频袁燕,99re久久精品国产,亚洲欧美日韩国产综合v,天天躁夜夜躁狠狠久久,激情五月婷婷激情五月婷婷

  • 回復
  • 收藏
  • 點贊
  • 分享
  • 發(fā)新帖

C#轉(zhuǎn)C++(數(shù)組復制、char轉(zhuǎn)16位無符號整數(shù))

數(shù)組復制:

C#實現(xiàn):

Copy(Array, Int32, Array, Int32, Int32)

復制 Array 中的一系列元素(從指定的源索引開始),并將它們粘貼到另一 Array 中(從指定的目標索引開始)。 長度和索引指定為 32 位整數(shù)。

c++實現(xiàn):

1.字符數(shù)組

使用strcpy

2.int,float,double等數(shù)組

使用memcpy,如復制一個長度為5 的 float數(shù)組,則代碼示例如下

int len = 5;

float a[len] = {1.0 ,1.1, 1.2, 1.3, 1.4};

float b[len];

memset(b, a, len*sizeof(float));

memcpy(b, a, len * sizeof(float));

注意,第三個參數(shù)不是指數(shù)組個數(shù),而是指要復制的數(shù)據(jù)的總字節(jié)數(shù)長度

字節(jié)數(shù)組(C++中unsigned char)轉(zhuǎn)16位整數(shù)

C#實現(xiàn):

[System.CLSCompliant(false)]
public static ushort ToUInt16 (byte[] value, int startIndex);

參數(shù)

value Byte[]

包含要轉(zhuǎn)換的兩個字節(jié)的字節(jié)數(shù)組。

startIndex Int32

value 內(nèi)的起始位置。

返回UInt16

由兩個字節(jié)構(gòu)成、從 startIndex 開始的 16 位無符號整數(shù)。

    byte[] byteArray = {
            15, 0, 0, 255, 3, 16, 39, 255, 255, 127 };

        BitConverter.ToUInt16( byteArray, 1 );
        BitConverter.ToUInt16( byteArray, 0 );
        BitConverter.ToUInt16( byteArray, 3 );
        BitConverter.ToUInt16( byteArray, 5 );
        BitConverter.ToUInt16( byteArray, 8 );
        BitConverter.ToUInt16( byteArray, 7 );

輸出:
index   array elements    ushort
-----   --------------    ------
    1            00-00         0
    0            0F-00        15
    3            FF-03      1023
    5            10-27     10000
    8            FF-7F     32767
    7            FF-FF     65535

C++中無符號字節(jié)數(shù)組轉(zhuǎn)無符號16位整數(shù)實現(xiàn):

#include <iostream>

using namespace std;
int main()
{
	unsigned char ch[4] = { 0xAA,0x11,0x02,0x04 };    //-----》使用uchar
	printf("%d  %d\n", *ch, *(ch + 1));
	printf("%x  %x\n", *ch, *(ch + 1));
	printf("uint8_t:%d  %d\n", *(uint8_t*)ch, *(uint8_t*)(ch + 1));//十進制
	printf("uint8_t:%x  %x\n", *(uint8_t*)ch, *(uint8_t*)(ch + 1));//十六進制
	printf("uint16_t:%d  %d\n", *(uint16_t*)ch, *(uint16_t*)(ch + 1));//十進制
	printf("uint16_t:%d  %d\n", *(uint16_t*)(ch+2), *(uint16_t*)(ch + 3));//十進制
	printf("uint16_t:%x  %x\n", *(uint16_t*)ch, *(uint16_t*)(ch + 1));//十六進制

	system("pause");
	return 0;
}

輸出:

全部回復(0)
正序查看
倒序查看
現(xiàn)在還沒有回復呢,說說你的想法
發(fā)