2016-01-25 28 views
-1

我编程C(ANSI C)一个POS(销售点)方法的位标志参数如何工作(Ansi C/C)?

我有这个功能

GetString(uchar *str,uchar mode,uchar minlen,uchar maxlen) 

是像readln但在POS

APImode参数是一样的东西D1,D2,D3 ......

但在(API的)的例子,我有这个

if(!GetString(buf, 0x26, 0, 10)) 
{ 
buf[buf[0]+1]=0; amt=atol(buf+1); 
} else { 
/* user press CANCEL button */ } 

那么,什么是介乎值为0x26(参数mode在功能)和 二进制数或位标志,甚至,我不知道,十六进制的关系。

在API那里有另一件事说明mode输入参数

1. Input mode definition: (priority order is bit3>bit4>bit5, and mode&0x38≠0); 
2. When inputting, the digit will be displayed on the screen in turns as plaintext or cryptograph (according to bit3). 
3. The initial cursor position is determined by ScrGotoxy(x, y). 
4. If bit7 of mode =1, then this function could bring initial digit string, and the string is displayed on initial cursor position as input digit string. 
5. Output string does not record and contain function keys. 
6. Press CLEAR button, if it is plaintext display, then CLEAR is considered as BACKSPACE key; if it is cryptograph display, then CLEAR is considered as the key to clear all contents. 
7. Use function key to switch to Capital mode. S80 uses Alpha key to select the corresponding character on a key, however SP30 uses UP and Down key, and T52 uses ―#‖ key, T620 uses key F2. 
8. In MT30, the switch method between uppercase, lowercase and number characters is to keep pressing 

回答

1

page you linked中有8位标志指定。在你的例子中,你有十六进制值0x26这是二进制值00100110。这指定了8位标志,其中3(D1,D2,D5)被置位,5(D0,D3,D4,D6,D7)清零。如果你引用你的表格链接(这是一个图形,所以我不能粘贴它),它告诉你GetString自变量mode指示函数的行为,对于8位标志集合(1)中的每一个,或清除(0)。

例如D2设置为1表示左对齐

组合各个标志给出一个二进制数,在您的示例中,该数字作为十六进制数0x26传递。

+0

我知道我的英语不好...但是,为什么我的问题有-2点:c我恐怕会失去我在stackOverflow中的帐户,你们真的帮我 –

1

的D1,D2,D3 ... D7是比特。我想它被用作一个标志。由于它只有1个字节,所以它有8种可能的状态,它们都可以组合在一起。

0x26是十进制38或二进制

00100110 

这意味着D1,D2,D5被设置和人的其它D的则不是。

+0

我该如何使用它? –

+1

阅读位标志。这是一个单字节,可以设置8个选项,你可以有组合 –

+0

好吧,我会这样做。但为什么是0x26?当在API中说这个值是针对某个或另一个模式的?我只能看到例子中的0x26。在函数中,只需说D1,D2,D6? –

0

这将帮助你,我定义了一个宏来操纵D7位,这是根据文档是ENTER模式的位。

以与其他模式相同的方式继续。

// bits manipulation 
// idx stand for bit index 

#define CHECK_BIT(var,idx)    ((var >> idx) & 1) 
#define SET_BIT(var,idx,n)    (var ^= (-(n?1:0)^var) & (1 << idx)) 


// helping macros 

// check if Enter mode is set D7 is used 
#define IS_ENTER_MODE_SET(mode)   CHECK_BIT(mode,7) 

// set Enter mode to opt (true,false) 
#define SET_ENTER_MODE (mode,opt)  SET_BIT(mode,7,opt)