c语言的入门函数 c语言函数使用方法( 六 )


(2)x||y||z ,只要x的值为真(非零),就不必判别y和z的值  , 整个表达式的值为1,只有x的值为假,才需要判别y的值,只有x和y的值同时为假才需要判别z的值,口诀:“一真必真” 。
?13 位运算
一、位运算符
在计算机中,数据都是以二进制数形式存放的,位运算就是指对存储单元中二进制位的运算 。C语言提供6种位运算符 。
二、位运算
位运算符|~∧ 按优先级从高到低排列的顺序是:
位运算符中求反运算“~“优先级最高,而左移和右移相同,居于第二,接下来的顺序是按位与 ““、按位异或 “∧“和按位或 “|“ 。顺序为~∧|。
例1左移运算符“”是双目运算符 。其功能把“ ”左边的运算数的各二进位全部左移若干位,由“”右边的数指定移动的位数,高位丢弃,低位补0 。
例 2右移运算符“”是双目运算符 。其功能是把“ ”左边的运算数的各二进位全部右移若干位,“”右边的数指定移动的位数 。
应该说明的是,对于有符号数,在右移时,符号位将随同移动 。当为正数时,最高位补0,而为负数时,符号位为1,最高位是补0或是补1 取决于编译系统的规定 。
例 3 设二进制数a是00101101  , 若通过异或运算a∧b 使a的高4位取反,低4位不变,则二进制数b是 。
解析:异或运算常用来使特定位翻转,只要使需翻转的位与1进行异或操作就可以了,因为原数中值为1的位与1进行异或运算得0 ,原数中值为0的位与1进行异或运算结果得1 。而与0进行异或的位将保持原值 。异或运算还可用来交换两个值,不用临时变量 。
所以本题的答案为: 11110000。
求C语言的基本函数?函数名:
difftime

能:
计算两个时刻之间的时间差

法:
double
difftime(time_t
time2,
time_t
time1);
程序例:
#include
#include
#include
#include
int
main(void)
{
time_t
first,
second;
clrscr();
first
=
time(NULL);
/*
Gets
system
time
*/
delay(2000);
/*
Waits
2
secs
*/
second
=
time(NULL);
/*
Gets
system
time
again
*/
printf("The
difference
is:
%f
\
seconds\n",difftime(second,first));
getch();
return
0;
}
函数名:
disable

能:
屏蔽中断

法:
void
disable(void);
程序例:
/***NOTE:
This
is
an
interrupt
service
routine.
You
cannot
compile
this
program
with
Test
Stack
Overflow
turned
on
and
get
an
executable
file
that
operates
correctly.
*/
#include
#include
#include
#define
INTR
0X1C
/*
The
clock
tick
interrupt
*/
void
interrupt
(
*oldhandler)(void);
int
count=0;
void
interrupt
handler(void)
{
/*
disable
interrupts
during
the
handling
of
the
interrupt
*/
disable();
/*
increase
the
global
counter
*/
count++;
/*
reenable
interrupts
at
the
end
of
the
handler
*/
enable();
/*
call
the
old
routine
*/
oldhandler();
}
int
main(void)

推荐阅读