Skip to content

Instantly share code, notes, and snippets.

@jimhester
Created April 29, 2016 11:29
Show Gist options
  • Save jimhester/e71d6968861dfc1321583563e32f0d50 to your computer and use it in GitHub Desktop.
Save jimhester/e71d6968861dfc1321583563e32f0d50 to your computer and use it in GitHub Desktop.
Decoing bitwise field
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