Created
April 29, 2016 11:29
-
-
Save jimhester/e71d6968861dfc1321583563e32f0d50 to your computer and use it in GitHub Desktop.
Decoing bitwise field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
decode_field <- function(x) { | |
nms <- c("No alarm", "Tape Break", "Beta Count Failure", "High Tape Delta Pressure (Tape Advance)", "Pressure Sensor Failure", "Flow Failure", "Nozzle Failure", "Internal Hardware (SPI bus) Failure", "Low Battery", "Delta Temperature Setpoint Exceeded", "Pump Over Temp 48C") | |
nms[bitwAnd(x, c(0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512)) > 0] | |
} | |
decode_field(8) | |
#> [1] "Pressure Sensor Failure" | |
decode_field(64 + 2) | |
#> [1] "Beta Count Failure" | |
#> [2] "Internal Hardware (SPI bus) Failure" | |
decode_field(1 + 32 + 128) | |
#> [1] "Tape Break" "Nozzle Failure" "Low Battery" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment