質問: 0 ; //DO5 ON } } ``` The above code shows, when the string is write in HyperTerminal, it will do some action to LED. For example, DO=0x1F will turn on all five LED. Because, based on the 0x1F in binary is IIIII (5-Bit). Is there any ways to simplify the code using bitwise function ?
回答: I see 2 easy reductions in code. Take the msg, "DO=0x00" and if this is the always case for the string, convert the last srting number into a number. Now you can use a classic switch to set those values. Next, why not set all 5 bit to off, and only set the bits you need in each case to on? Those 2 alone could shrink the source by half the lines. Now back to school. If I wanted to be really clever I'd look at this as if it was a circuit and use a circuit optimizer to reduce it to a truth table.