📄 methoda.cpp
字号:
#include "stdafx.h"
#include "GPIOCTL.h"
#include <winioctl.h>
#include "methoda.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
void Cmethoda::tenTotwo(int *a, int b)
{
int x;
char sign;
char i;
for (x=0;x<b;x++)
{
i=0;
if(*(a+i)==0)
{
*(a+i)=1;
sign=0;
}
else
{
*(a+i)=0;
++i;
sign=1;
}
while(sign==1)
{
if(*(a+i)==0)
{
*(a+i)=1;
sign=0;
}
else
{
*(a+i)=0;
++i;
sign=1;
}
}
}
}
int Cmethoda::twoTOten(int *a)
{
int b,c,d,e,f,j,h,i,g;
c=(*a)*2;
d=(*(a+1))*2;
e=(*(a+2))*2;
f=(*(a+3))*2;
j=(*(a+4))*2;
h=(*(a+5))*2;
i=(*(a+6))*2;
g=(*(a+7))*2;
b=(powi(g,7)+powi(i,6)+powi(h,5)+powi(j,4)+powi(f,3)+powi(e,2)+powi(d,1)+powi(c,0));
return b;
}
int Cmethoda::powi(int a, int b)
{
int c,d,e;
d=b;
c=a;
e=a;
if(a==0)
{
c=0;
return c;
}
if(b==0)
{
c=1;
return c;
}
while(d>1)
{
c=c*e;
--d;
}
return c;
}
void Cmethoda::bitTOchar(unsigned char *value, int bitcount,int bitvalue)
{
if(bitcount>7||bitcount<0||bitvalue>1||bitvalue<0)
{
return;
}
int bit[8]={0,0,0,0,0,0,0,0};
int *p;
p=bit;
tenTotwo(p,*value);
bit[bitcount]=bitvalue;
*value=twoTOten(p);
}
void Cmethoda::not(int *bit)
{
if(*bit>1||*bit<0)
{
return;
}
if(*bit==0)
{
*bit=1;
return;
}
if(*bit==1)
{
*bit=0;
return;
}
}
int Cmethoda::readbitfromchar(unsigned char *valuea, int bitcount)
{
if(bitcount>7||bitcount<0)
{
return 2;//错误则返回2
}
int bit[8]={0,0,0,0,0,0,0,0};
int *p;
p=bit;
tenTotwo(p,*valuea);
return bit[bitcount];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -