#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

typedef unsigned char Byte;

Byte * intToBytes(const int& N) {

Byte* byte = new Byte[4];

byte[0] = (N >> 24) & 0xFF;
byte[1] = (N >> 16) & 0xFF;
byte[2] = (N >> 8) & 0xFF;
byte[3] = N & 0xFF;

return byte;
}

// 将一个byte数组、一个整数、一个整数以及一个byte数组组合为一个byte数组,并返回。
Byte * Cat(Byte *a, int b, int c, Byte *d)
{
Byte* res = new Byte[12];
memcpy(res, a, 2);// 2 为数组a的长度
memcpy(res + 2, intToBytes(b), 4);// 2 为int的长度
memcpy(res + 6, intToBytes(c), 4);
memcpy(res + 10, d, 2);// 2 为数组a的长度
return res;
}

int main()
{
Byte a[2]={253,27};
int b=16;
int c=18;
Byte d[2]={222,92};

Byte * res = Cat(a, b, c, d);
cout<<res<<endl;
// for (int i = 0; i < 12; i++)
// printf("%c", res[i]);
return 0;
}

最新文章

  1. 如何保存gnome的linux的 会话?相当于windows下的休眠?
  2. 关于图片的PNG与JPG、JIF格式
  3. spring security自定义拒绝访问页面
  4. VC++6.0 显示行号
  5. Cookielib
  6. Catharanthus roseus(长春花碱)的生物合成
  7. 《Pro Android Graphics》读书笔记之第三节
  8. WCF 学习笔记之双工实现
  9. Linux下查看access访问日志IP统计命令
  10. PhpStorm11.0 配置在浏览器中打开文件
  11. MIME协议在邮件中的应用详解
  12. Redefine:Change in the Changing World
  13. Codeforces Round #349 (Div. 1)E. Forensic Examination
  14. DOM编程艺术推荐的addLoadEvent和insertAfter
  15. [译]javascript中的依赖注入
  16. 作为sort()方法的参数的比较函数(高程三第五章)
  17. struts2基本配置详解2
  18. bug管理工具
  19. HDU 2135 Rolling table
  20. MySQL 第五天

热门文章

  1. whatsoever|
  2. java中的深拷贝
  3. docker实践-安装wordpress
  4. MyBatis之一级缓存及其一级缓存失效
  5. Android 代码混淆规则
  6. CentOS7安装Ceph
  7. React Native 学习笔记--进阶(二)--动画
  8. 查看网卡信息 - ethtool
  9. 【原创】从零开始搭建Electron+Vue+Webpack项目框架(六)Electron打包,同时构建客户端和web端
  10. SpringBoot入门系列(一)如何快速创建SpringBoot项目