unsigned

float uint32 uint16 转为uint8

依然范特西╮ 提交于 2020-01-18 17:35:25
appendUint32ToVec(std::vector<unsigned char> & vec, unsigned int val, bool bigEndian ) { if (bigEndian) { // unsigned char* p = (unsigned char*) &val; // p += 3; // vec.push_back(*p--); // vec.push_back(*p--); // vec.push_back(*p--); // vec.push_back(*p); uint8_t p = (val>>24)&0xFF; vec.push_back(p); p = (val>>16)&0xFF; vec.push_back(p); p = (val>>8)&0xFF; vec.push_back(p); p = (val&0xFF); vec.push_back(p); } else { // unsigned char* p = (unsigned char*) &val; // vec.push_back(*p++); // vec.push_back(*p++); // vec.push_back(*p++); // vec.push_back(*p++); uint8_t p = (val&0xFF); vec.push_back(p

C语言学习系列:位域

浪尽此生 提交于 2020-01-18 13:55:53
所谓"位域"是把一个字节中的二进位划分为几个不同的区域,并说明每个区域的位数。每个域有一个域名,允许在程序中按域名进行操作。这样就可以把几个不同的对象用一个字节的二进制位域来表示。 位域声明 struct bitFieldName { type [member_name] : width ; }exampleVar; 在结构体定义时,我们可以指定某个成员变量所占用的二进制位数(Bit),这就是位域。 位域的宽度不能超过它所依附的数据类型的长度。通俗地讲,成员变量都是有类型的,这个类型限制了成员变量的最大长度, : 后面的数字不能超过这个长度。 只有有限的几种数据类型可以用于位域。这几种数据类型是 int、signed int 和 unsigned int,_Bool 。但编译器在具体实现时都进行了扩展,额外支持了 char、signed char、unsigned char 以及 enum 类型。 位域的存储 位域的具体存储规则如下: 1.当相邻成员的类型相同时,如果它们的位宽之和小于类型的 sizeof 大小,那么后面的成员紧邻前一个成员存储,直到不能容纳为止;如果它们的位宽之和大于类型的 sizeof 大小,那么后面的成员将从新的存储单元开始,其偏移量为类型大小的整数倍。 #include <stdio.h> int main(){ struct bs{ unsigned m:

性能测试基础-SOCKET协议用例

僤鯓⒐⒋嵵緔 提交于 2020-01-18 13:32:39
1.首先在进行性能测试的时候,我们要了解软件的通信协议是什么,我们使用什么协议,如何去模拟。SOCKET协议主要应用于在C/S模式的系统。 作者本人已当初做过的C/S架构的系统做的脚本录制,在上面做脚本的参数化以及优化工作。脚本如下: #include "lrs.h" #include <sub1.h> #include <sub2.h>//包含了2个自定义的C函数。LR不支持C++的函数库。C++函数需要做修改 Action() { unsigned char cLine[2048]={0}; unsigned char cOut[2048]={0}; unsigned char cOut2[2048]={0}; unsigned char retu1[2048]={0}; int len = 0; int len1 = 0; int rc,i,re; lr_start_transaction("Conn_socket"); rc = lrs_create_socket("socket0", "TCP", "RemoteHost=127.0.0.1:22222", LrsLastArg);//创建SOCKET连接 //lr_output_message("rc=%d",rc); //连接成功返回判断 if (rc != 0 ) { lr_end_transaction("Conn

文件操作函数(2)

不打扰是莪最后的温柔 提交于 2020-01-18 08:02:00
一、块读写 块读写主要涉及到两个函数fread和fwrite,这两个函数的原型是: unsigned int fread(void *buffer,unsigned int size,unsigned int n,FILE *fp); 从文件读取一组数据存放在首地址为buffer的内存空间中,size为一个数据块的大小,n为要读取的数据块的个数,若读取成功,则返回读取的数据的数据块的个数,否则返回0. unsigned int fwrite(const void *buffer,unsigned int size,unsigned int n,FILE *fp); 向文件中写入数据,写入成功返回写入数据块的个数,否则返回0. 块读写一般用于结构体。 注意: 1)块读写常用于结构体。 2)fread和fwrite一般成对出现,如果对文件进行写操作用的是fwrite,则用fread读取,否则可能会得到意想不到的结果。 二、格式化读写 格式化读写主要涉及到两个函数:fscanf和fprintf,两个函数的原型是 int fscanf(FILE *fp,const char *format[,argument]....); 用于从文件格式化读取数据,若读取成功,则返回读取的数据个数,否则返回-1 int fprintf(FILE *fp,const char *format[

工程实践_GPIO介绍

蹲街弑〆低调 提交于 2020-01-17 06:26:11
一.GPIO简介 GPIO(General-Purpose IO ports),也就是通用IO口。在嵌入式系统中常常有数量众多,但是结构却比较简单的外部设备/电路,对于这些设备/电路有的需要CPU为之提供控制手段,有的则需要被CPU用作输入信号。而且,许多这样的设备/电路只要求一位,即只要有开/关两种状态就够了,比如灯亮与灭。对于这些设备/电路的控制,使用传统的串行口或并行口都不合适。所以在微控制芯片上一般都会提供一个“通用可编程IO接口”,也就是GPIO。 GPIO接口至少有两个寄存器,即“通用IO控制寄存器”与“通用IO数据寄存器”。数据寄存器的各位都直接引到芯片外部,而对数据寄存器中每一位的作用,即每一位的信号流通方向是输入还是输出,则可以通过控制寄存器中对应位独立的加以设置。这样,有无GPIO接口也就成为微控制器区别于微处理器的一个特征。 在实际的MCU中,GPIO是有多种形式的。比如,有的数据寄存器可以按照位寻址,有些却不能按照位寻址,这在编程时就要区分了。比如传统的8051系列,就区分成可位寻址和不可位寻址两种寄存器。另外,为了使用的方便,很多MCU把glue logic等集成到芯片内部,增强了系统的稳定性能,比如GPIO接口除去两个标准寄存器必须具备外,还提供上拉寄存器,可以设置IO的输出模式是高阻,还是带上拉的电平输出,或者不带上拉的电平输出。这在电路设计中

Arduino初级教程

淺唱寂寞╮ 提交于 2020-01-16 00:26:29
目录 1. Arduino概述 2.Arduino板 3.Arduino安装 4.Arduino程序结构 5.Arduino数据类型 6.Arduino变量 7.Arduino运算符 8.Arduino控制语句 9.Arduino循环 10.Arduino函数 11.Arduino字符串及字符串对象 12.Arduino时间函数 13.Arduino数组 14.Arduino函数库 (1)Arduino I/O函数 (2)Arduino字符函数 (3)Arduino数学库 (4)Arduino三角函数 1. Arduino概述 Arduino是一个基于易用硬件和软件的原型平台。由可编程电路板和Arduino IDE的软件组成,将计算机代码写入并上传到物理板。 特点: 板卡读取来自传感器的模拟或者数字输入信号,转换为输出。 通过IDE向板上的微控制器发送一组指令控制板功能。 使用USB线将代码加载到电路板上。 2.Arduino板 板名称 工作电压 时钟速度 数字I/O 模拟输入 PWM UART 编程接口 Arduino UNO R3 5V 16MHZ 14 6 6 1 USB通过ATMega16U2 使用板如下: 组成部件 电源USB:板卡使用PC机的USB线供电。 电源(桶插座):板卡可以直接从交流电源供电。 稳压器:控制提供给板卡的电压,稳定处理器和其他元件的直流电压。

How do I byte-swap a signed number in C?

自古美人都是妖i 提交于 2020-01-14 16:35:36
问题 I understand that casting from an unsigned type to a signed type of equal rank produces an implementation-defined value: C99 6.3.1.3: Otherwise, the new type is signed and the value cannot be represented in it; either the result is implementation-defined or an implementation-defined signal is raised. This means I don't know how to byte-swap a signed number. For instance, suppose I am receiving two-byte, twos-complement signed values in little-endian order from a peripheral device, and

How do I byte-swap a signed number in C?

你。 提交于 2020-01-14 16:32:31
问题 I understand that casting from an unsigned type to a signed type of equal rank produces an implementation-defined value: C99 6.3.1.3: Otherwise, the new type is signed and the value cannot be represented in it; either the result is implementation-defined or an implementation-defined signal is raised. This means I don't know how to byte-swap a signed number. For instance, suppose I am receiving two-byte, twos-complement signed values in little-endian order from a peripheral device, and

How do I byte-swap a signed number in C?

久未见 提交于 2020-01-14 16:32:06
问题 I understand that casting from an unsigned type to a signed type of equal rank produces an implementation-defined value: C99 6.3.1.3: Otherwise, the new type is signed and the value cannot be represented in it; either the result is implementation-defined or an implementation-defined signal is raised. This means I don't know how to byte-swap a signed number. For instance, suppose I am receiving two-byte, twos-complement signed values in little-endian order from a peripheral device, and

在一张图片中隐藏另一张图片

我的梦境 提交于 2020-01-14 11:42:48
首先是在灰度图中隐藏灰度图 因为是交作业嘛,为了简单就依次在每个字节中隐藏信息,如果有什么不想让人看见的东西要隐藏,可以自己有选择性的隐藏 这里先得到两张灰度图 将第二幅图片当作秘密图片插入一图,这里先将第二幅图置乱 这里采用的是菱形置乱的方法,即在菱形中从第一行开始从左向右依次写入1到n,替换时从第一列从上到下依次读取序号,即第一列序号对应的像素作为第一个像素 代码如下,这里我用的算法比较笨就将就吧,恢复置乱时只需要更改其中一条代码,在代码中已说明 再说明一下,我是将菱形补全为正方形,用0填充,方法虽笨但是能用 /* 对图片进行置乱处理 2015年6月2日20:02:18 blog:http://www.cnblogs.com/wd1001/ */ #include<stdio.h> #include<malloc.h> #include<stdlib.h> /* 位图头结构 */ #pragma pack(1) typedef struct tagBITMAPFILEHEADER { unsigned char bfType[2];//文件格式 unsigned long bfSize;//文件大小 unsigned short bfReserved1;//保留 unsigned short bfReserved2; unsigned long bfOffBits; /