Start New Discussion within our Software Development Community

Hi, how to make counting numbers ?
For example, I send command to HyperTerminal, then it will reply (print) counted values.

Here the first example,

send command: UI1-UI10
reply command: UI1-UI10_in_Hexadecimal:0x3FF

The above example, Ui1 until Ui10, it count, one until ten. Then, the binary will have IIIIIIIIII (10bit), but in HyperTerminal will reply 0x3FF in hexadecimal.

2nd Example,

send command: UI5-UI7
reply command: UI5-UI7_in_Hexadecimal:0x3 or 0x03

Ui5 until Ui7, it count, five until seven. Then, the binary will have III (3bit), but in HyperTerminal will reply 0x3 or 0x03 in hexadecimal.

3rd example,

send command: UI5-UI5
reply command: UI5-UI5_in_Hexadecimal:0x1

Ui5 until Ui5, it count, five only. Then, the binary will have I (1bit), but in HyperTerminal will reply 0x1 or 0x01 in hexadecimal.

can the above example done it bitwise function ?

here my code :

void decode(unsigned char* msg) {

    unsigned char* lala[50];

    if (strstr(msg, "UI1-UI10") != NULL)
    {
        sprintf(lala, "UI1-UI10_in_Hexadecimal:0x3FF");
        sendString(lala);
    }
    else if (strstr(msg, "UI5-UI7") != NULL)
    {
        sprintf(lala, "UI5-UI7_in_Hexadecimal:0x3");
        sendString(lala);
    }
    else if (strstr(msg, "UI5-UI5") != NULL)
    {
        sprintf(lala, "UI5-UI5_in_Hexadecimal:0x1");
        sendString(lala);
    }
}

But, from this code got problem when the send command is different.

It looks like you are hard coding each possible answer. It would take pages to exhaust every possibility. Maybe try splitting the input on -, and parsing the two values you need (using strsep() and sscanf()). Once you have the two values, you can calculate whatever value you need.

This article has been dead for over six months. Start a new discussion instead.