user3484325
user3484325

Reputation: 11

Finding most significant bit in linux

I am working on raspberry pi, for the command :

char-write-req 0x0011 e00000e0

I am getting ouput1 as:

12 57 7e 35 2d 49

Similarly,

char-write-req 0x0011 e00100e1

output2 is:

23 45 76 3e 66 2d

In a similar way I am getting output for different commands, now I want to check for MSB and pass that bit in switch case i.e I want "1" from 12 of ouput1 and "2" from 23 of output2 and generate a switch case for that. How can i do this?

Upvotes: 0

Views: 71

Answers (1)

Krzysztof Krasoń
Krzysztof Krasoń

Reputation: 27486

Use cut -c 1 to get the first character from the output:

char-write-req 0x0011 e00000e0 | cut -c 1

For the case you use:

case `char-write-req 0x0011 e00000e0 | cut -c 1` in                               
    1) echo "something" ;;                                                      
    2) echo "something else" ;;                                                 
esac

Upvotes: 1

Related Questions