Hi all.
I need a good way of extracting values from certain bits inside a unsigned short:
The definition of the 4 alarms inside the ushort:
Name......Range .......Bits
Alarm4....0-15....13/16-16/16
Alarm3....0-15....9/16-12/16
Alarm2....0-15....5/16-8/16
Alarm1....0-15....1/16-4/16
The value of the ushort: 4383 or (1000100011111 in binary)
So what i want to achieve is:
100110011001100 1
Alarm1.....Alar m2.....Alarm3.. ....Alarm4
1001.......1001 .......1001.... ....1001
Gets translated into:
Alarm1....Alarm 2....Alarm3.... Alarm4
9............9. ...........9... .........9
Using the pseudo code:
Thank you very much in advance for your time.
Regards,
Johan
I need a good way of extracting values from certain bits inside a unsigned short:
The definition of the 4 alarms inside the ushort:
Name......Range .......Bits
Alarm4....0-15....13/16-16/16
Alarm3....0-15....9/16-12/16
Alarm2....0-15....5/16-8/16
Alarm1....0-15....1/16-4/16
The value of the ushort: 4383 or (1000100011111 in binary)
So what i want to achieve is:
100110011001100 1
Alarm1.....Alar m2.....Alarm3.. ....Alarm4
1001.......1001 .......1001.... ....1001
Gets translated into:
Alarm1....Alarm 2....Alarm3.... Alarm4
9............9. ...........9... .........9
Using the pseudo code:
Code:
getValueFunc(ushort bits, int offset); ushort u = 4383; UInt16 Alarm1Value = getValueFunc(u, 1); UInt16 Alarm2Value = getValueFunc(u, 5); UInt16 Alarm3Value = getValueFunc(u, 9); UInt16 Alarm4Value = getValueFunc(u, 13);
Thank you very much in advance for your time.
Regards,
Johan
Comment