c++ - 如何连接二进制宏值?什么是二进制类型?

标签 c++ binary concatenation arduino-c++

从事使用二进制命令代码的 arduino 项目。

采样率和滤波器类型是两个串联的代码。 采样率 = MSB 一半,滤波器类型 = LSB 一半。

找到:Bitwise concatenation in C

#include <stdio.h>
int main() {

    int first = 0b1010;
              //^^v See here
    int second = 0b0011;
    int result = (first << 4) | second;
    printf("%d", result);

    return 0;

其中展示了如何连接两个二进制值并将它们相加。

.h 文件 中的所有二进制代码作为宏。 我可以对纯二进制值做同样的事情吗?什么类型? 将使用串联的二进制值 - 作为函数中的命令。

Usage of binary code command currently Looks Like

所有的宏:

    //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.

最佳答案

这将是完全相同的代码。宏将替换为二进制文字,文字将被提升为整数,然后左移后跟或运算符将被调用。

关于c++ - 如何连接二进制宏值?什么是二进制类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57222679/

相关文章:

python - 连接大的 numpy 数组

c++ - 错误 : assignment of member ‘x::x’ in read-only object

c++ - 为什么迭代器调试在调试版本中会减慢 std::unordered_map 200x?

c++ - Credential Provider 上的禁用区域

python - Python中的二进制缓冲区

mysql - 如何在没有连续切割的情况下使用 mysql group_concat(concat())

python - 连接多个 .fasta 文件

c++ - 一个简单的 C++ 函数,在不同的计算机上有不同的答案

python - 如何使用 bitstring 包将 float 输入为 '0' 和 '1' 字符的字符串?

algorithm - 为什么二进制搜索索引以这种方式计算?