C++ 如何连接二进制宏值?什么是二进制类型?
正在处理使用二进制命令代码的arduino项目 采样率和过滤器类型是两个串联的代码。 采样率=MSB一半,过滤器类型=LSB一半 发现:C++ 如何连接二进制宏值?什么是二进制类型?,c++,binary,concatenation,arduino-c++,C++,Binary,Concatenation,Arduino C++,正在处理使用二进制命令代码的arduino项目 采样率和过滤器类型是两个串联的代码。 采样率=MSB一半,过滤器类型=LSB一半 发现: 这将是完全相同的代码。宏将被二进制文字替换,文字将被提升为整数,然后将调用左移位和or运算符。欢迎使用堆栈溢出。请阅读,采取,阅读,以及。最后,请学习如何创建(代码)。尽可能避免宏,尤其是当你在C++中编码的时候,有更好的方法来做这样的事情。@ MarekR真是一个莫名其妙的评论。很明显,宏来自外部源。AFAIK Arduino Uno有16位int。使用Ad
这将是完全相同的代码。宏将被二进制文字替换,文字将被提升为整数,然后将调用左移位和or运算符。欢迎使用堆栈溢出。请阅读,采取,阅读,以及。最后,请学习如何创建(代码)。尽可能避免宏,尤其是当你在C++中编码的时候,有更好的方法来做这样的事情。@ MarekR真是一个莫名其妙的评论。很明显,宏来自外部源。AFAIK Arduino Uno有16位int。使用AdaFruit“Arduino”nRF52832
#include <stdio.h>
int main() {
int first = 0b1010;
//^^v See here
int second = 0b0011;
int result = (first << 4) | second;
printf("%d", result);
return 0;
//Sample Rate and Filter Type Codes From ADS1261 Datasheets
/*Binary Code Commands Defining Sampling Rate and Filter Type - http://www.ti.com/lit/ds/symlink/ads1261.pdf#page=61*/
//ADC DATA RATE
#define SPS_2_PT_5 0b00000 //SPS = 2.5
#define SPS_5 0b00001 //SPS = 5
#define SPS_10 0b00010 //SPS = 10
#define SPS_16_PT_6 0b00011 //SPS = 16.6
#define SPS_20_DEFAULT 0b00100 //SPS = 20 <--- this is also the default.
#define SPS_50 0b00101 //SPS = 50
#define SPS_60 0b00110 //SPS = 60
#define SPS_100 0b00111 //SPS = 100
#define SPS_400 0b01000 //SPS = 400
#define SPS_1200 0b01001 //SPS = 1200
#define SPS_2400 0b01010 //SPS = 2400
#define SPS_4800 0b01011 //SPS = 4800
#define SPS_7200 0b01100 //SPS = 7200
#define SPS_14400 0b01101 //SPS = 14400
#define SPS_19200 0b01110 //SPS = 19200
#define SPS_25600 0b00110 //SPS = 25600
#define SPS_40000 0b10000 //SPS (f_CLK - 10.24 MHz)
//Define Filter Types
#define F_SINC1 0b000 //SINC1
#define F_SINC2 0b001 //SINC2
#define F_SINC3 0b010 //SINC3
#define F_SINC4 0b011 //SINC4
#define F_FIR 0b100 //FIR// Default if not specified.