⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shifts.c

📁 sdcc是为51等小型嵌入式cpu设计的c语言编译器支持数种不同类型的cpu
💻 C
字号:
/** Tests covering the shift operators.    disabled for pic16    sign: signed, unsigned    type: char, int, long    storage: static,     attr: volatile    vals: 3    pending - 1792, 851968, 1560281088, -3, -1792, -851968, -1560000000*/#include <testfwk.h>voidtest1ShiftClasses(void){    {attr} {storage} {sign} {type} i, result;    i = 30;    ASSERT(i>>3 == 3);    ASSERT(i<<2 == 120);        result = i;    result >>= 2;    ASSERT(result == 7);    result = i;    result <<= 2;    ASSERT(result == 120);}voidtest2ShiftRight(void){    {attr} {storage} {type} i, result;    i = -120;    ASSERT(i>>1 == -60);    ASSERT(i>>2 == -30);    ASSERT(i>>3 == -15);    ASSERT(i>>4 == -8);    ASSERT(i>>5 == -4);    ASSERT(i>>6 == -2);    ASSERT(i>>7 == -1);    ASSERT(i>>8 == -1);    result = i;    result >>= 3;    ASSERT(result == -15); }voidtest3ShiftByteMultiples(void){    {attr} {storage} {type} i;    i = ({type}){vals};    ASSERT(i>>8  == ({type})({vals} >> 8));    ASSERT(i>>16 == ({type})({vals} >> 16));    ASSERT(i>>24 == ({type})({vals} >> 24));    i = ({type}){vals};    ASSERT( ({type})(i<<8)  ==  ({type})({vals} << 8));;    ASSERT((({type}) i<<16) == (({type}) {vals} << 16));    ASSERT((({type}) i<<24) == (({type}) {vals} << 24));}voidtest4ShiftOne(void){    {attr} {storage} {sign} {type} i;    {sign} {type} result;    i = ({type}){vals};    result = i >> 1;    ASSERT(result == ({type})(({type}){vals} >> 1));    result = i;    result >>= 1;    ASSERT(result == ({type})(({type}){vals} >> 1));    result = i << 1;    ASSERT(result == ({type})(({type}){vals} << 1));    result = i;    result <<= 1;    ASSERT(result == ({type})(({type}){vals} << 1));}static {type} ShiftLeftByParam ({type} count){    {attr} {storage} {type} i;    i = ({type}){vals};    return (i << count);}static {type} ShiftRightByParam ({type} count){    {attr} {storage} {type} i;    i = ({type}){vals};    return (i >> count);}voidtestShiftByParam(void){    ASSERT(ShiftLeftByParam(2)  == ({type})({vals} << 2));    ASSERT(ShiftRightByParam(2) == ({type})({vals} >> 2));}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -