From 75d9da194ab102359dd92cad370f5683564c6490 Mon Sep 17 00:00:00 2001 From: feilong Date: Sat, 23 Oct 2021 21:55:26 +0800 Subject: [PATCH] add bit op --- .../bit_op.json" | 5 ++ .../bit_op.md" | 58 +++++++++++++++++++ .../config.json" | 4 +- .../bit_field.md" | 2 +- 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 "data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/3.\344\275\215\350\277\220\347\256\227/5.\344\275\215\351\200\273\350\276\221\350\277\220\347\256\227\347\254\246/bit_op.json" create mode 100644 "data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/3.\344\275\215\350\277\220\347\256\227/5.\344\275\215\351\200\273\350\276\221\350\277\220\347\256\227\347\254\246/bit_op.md" diff --git "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/3.\344\275\215\350\277\220\347\256\227/5.\344\275\215\351\200\273\350\276\221\350\277\220\347\256\227\347\254\246/bit_op.json" "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/3.\344\275\215\350\277\220\347\256\227/5.\344\275\215\351\200\273\350\276\221\350\277\220\347\256\227\347\254\246/bit_op.json" new file mode 100644 index 0000000..24fad56 --- /dev/null +++ "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/3.\344\275\215\350\277\220\347\256\227/5.\344\275\215\351\200\273\350\276\221\350\277\220\347\256\227\347\254\246/bit_op.json" @@ -0,0 +1,5 @@ +{ + "type": "code_options", + "author": "幻灰龙", + "source": "bit_op.md" +} \ No newline at end of file diff --git "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/3.\344\275\215\350\277\220\347\256\227/5.\344\275\215\351\200\273\350\276\221\350\277\220\347\256\227\347\254\246/bit_op.md" "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/3.\344\275\215\350\277\220\347\256\227/5.\344\275\215\351\200\273\350\276\221\350\277\220\347\256\227\347\254\246/bit_op.md" new file mode 100644 index 0000000..07b7876 --- /dev/null +++ "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/3.\344\275\215\350\277\220\347\256\227/5.\344\275\215\351\200\273\350\276\221\350\277\220\347\256\227\347\254\246/bit_op.md" @@ -0,0 +1,58 @@ +# 位逻辑运算 + +下列错误的代码是? + +## 答案 + +```c +#include +#include + +int main(int argc, char** argv){ + int i = 1; + assert(i<<1==4); + return 0; +} + +``` + +## 选项 + +### 选项1 + +```c +#include +#include + +int main(int argc, char** argv){ + int i = 2; + assert(i>>1==1); + return 0; +} +``` + +### 选项2 + +```c +#include +#include + +int main(int argc, char** argv){ + int i = 3; + assert((i&2)==2); + return 0; +} +``` + +### 选项3 + +```c +#include +#include + +int main(int argc, char** argv){ + int i = 1; + assert((i|2)==3); + return 0; +} +``` \ No newline at end of file diff --git "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/3.\344\275\215\350\277\220\347\256\227/5.\344\275\215\351\200\273\350\276\221\350\277\220\347\256\227\347\254\246/config.json" "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/3.\344\275\215\350\277\220\347\256\227/5.\344\275\215\351\200\273\350\276\221\350\277\220\347\256\227\347\254\246/config.json" index f13fb23..bafbbee 100644 --- "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/3.\344\275\215\350\277\220\347\256\227/5.\344\275\215\351\200\273\350\276\221\350\277\220\347\256\227\347\254\246/config.json" +++ "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/3.\344\275\215\350\277\220\347\256\227/5.\344\275\215\351\200\273\350\276\221\350\277\220\347\256\227\347\254\246/config.json" @@ -6,5 +6,7 @@ "C语言" ], "children": [], - "export": [] + "export": [ + "bit_op.json" + ] } \ No newline at end of file diff --git "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/3.\344\275\215\350\277\220\347\256\227/7.\344\275\215\345\255\227\346\256\265/bit_field.md" "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/3.\344\275\215\350\277\220\347\256\227/7.\344\275\215\345\255\227\346\256\265/bit_field.md" index 9133d49..be5f79e 100644 --- "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/3.\344\275\215\350\277\220\347\256\227/7.\344\275\215\345\255\227\346\256\265/bit_field.md" +++ "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/3.\344\275\215\350\277\220\347\256\227/7.\344\275\215\345\255\227\346\256\265/bit_field.md" @@ -1,4 +1,4 @@ -# 十六进制转换 +# 位字段(bit filed) 利用位域,你能声明比字符宽度更小的成员,低至1位。假设机器字是8 bytes,下面的结构体大小是? -- GitLab