文档介绍:位运算
1、在指定位置插入结点的操作void indert(void){ char numstr[20]; if (head==NULL) return; this=heae; printf(“input num”); gets(numstr); do { if (this->num==atol(numstr)) { new=(struct stud *)malloc(sizeof(struct stud)); new->next=this->next; this-next=new; gets(new->name); : } this=this->next; }while(this!=NULL); }
2、删除指定结点的操作void delete(void){ char numstr[20]; if (head==NULL) return; this=heae;new=this; printf(“input num”); gets(numstr); do { if (new->num==atol(numstr)) if ( head==new) head=new->next; else this->next=new->next; this=new; new=new->next; }while(new!=NULL); }
本次课内容:位运算概述和位运算使用方法教学目的:掌握相关概念、定义、运算符和引用方法。重点:相关概念,运算符、定义、引用。难点:引用及特殊环境的引用。预习:二进制表示方法,原码、反码和补码。有符号数和无符号数。
一、位运算概述1、位状态和位运算(1)数据以二进制表示时的信号每一位的0或1的状态,称为一个“位”(bit)的状态。如:10011001(2)对数据的某些位进行的操作。如:接位取反等。2、运算符 位运算符含义举例 ~ 按位取反 ~a,对变量a中全部位取反 << 左移 a<<2,a中各位全部左移2位 >> 右移 a>>2, a中各位全部右移2 位 & 按位与 a&b, a和b中各位按位进行“与”运算 | 按位或 a | b ,a和b各位按位进行“或”运算 ^ 按位异或 a^b, a和b中各位按位进行“异或”运算
位运算赋值操作 运算符 含义举例等价于 &= 位与赋值 a&=b a=a&b |= 位或赋值 a | =b a= a | b ^= 位异或赋值 a^=b a=a^b >>= 右移赋值 a>>=b a=a>>b <<= 左移赋值 a<<=b a=a<<b二、位运算使用方法1、与运算(char a,b;) 如: a= 0 0 0 0 1 0 0 0 a= 1 1 1 1 1 0 0 0 & b= 0 0 0 1 1 0 0 0 &b= 0 0 0 1 1 0 0 0 a&b= 0 0 0 0 1 0 0 0 a&b= 0 0 0 1 1 0 0 0 屏蔽高四位屏蔽低四位 a=0x6A,b=0x0F a= - 0x6A,b=0xF0 a= 0 1 1 0 1 0 1 0 a= 0 1 1 0 1 0 1 0 & b= 0 0 0 0 1 1 1 1 &b=