Learn R Programming

BMS (version 0.3.4)

bin2hex: Converting Binary Code to and from Hexadecimal Code

Description

A simple-to-use function for converting a logical ('binary') vector into hex code and reverse.

Usage

bin2hex(binvec)
hex2bin(hexcode)

Arguments

binvec
a logical vector (alternatively a vector coercible into logical)
hexcode
a single-element character denoting an integer in hexcode (admissible character: 0 to 9, ato f)

Value

bin2hex returns a single element character; hex2bin returns a numeric vector equivalent to a logical vector

Details

The argument is an integer in binary form (such as "101"), provided as a logical (c(T,F,T)) or numeric vector (c(1,0,1)). bin2hex then returns a character denoting this number in hexcode (in this case "5"). The function hex2bin does the reverse operation, e.g. hex2bin("5") gives (c(1,0,1)).

See Also

hex2bin for converting hexcode into binary vectors, format.hexmode for a related R function.

Check http://bms.zeugner.eu for additional help.

Examples

Run this code
  bin2hex(c(TRUE,FALSE,TRUE,FALSE,TRUE,TRUE))
  bin2hex(c(1,0,1,0,1,1))
  hex2bin("b8a")
  bin2hex(hex2bin("b8a"))

Run the code above in your browser using DataLab