Skip to content

Instantly share code, notes, and snippets.

@jimhester
jimhester / decode_bitwise.R
Created April 29, 2016 11:29
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)