#' Function to convert Two's Complement integer to a standard integer.
#'
#' \code{twos_complement} is vectorised and will convert integers to-and-from
#' (20-bit) binary form to decode the Two's Complement rule.
#'
#' @param x Vector of 20-bit integers.
#'
#' @author Alexandre Ilha and Stuart K. Grange.
#'
#' @return Numeric vector.
#'
#' @examples
#'
#' # A hexadecimal number
#' hex <- "fff4d"
#'
#' # Hexadecimal as a base 10 decimal
#' integer <- strtoi(hex, 16)
#' integer
#' 1048397
#'
#' # Decode the Two's Complement rule
#' twos_complement(integer)
#' -179
#'
#' @export
twos_complement <- function(x) ifelse(x > (2^19 - 1), x - 2^20, x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.