Main Content

hexToBinaryVector

Convert hexadecimal value to binary vector

Description

This function is part of Data Acquisition Toolbox™, and converts hexadecimal data to binary data represented by a vector of 1s and 0s. To convert to binary data as a character vector, you can use the MATLAB® functions hex2dec and dec2bin. See Hexadecimal and Binary Values.

example

binVal = hexToBinaryVector(hexNumber) converts hexadecimal numbers to a binary vector.

example

binVal = hexToBinaryVector(hexNumber,numberOfBits) converts hexadecimal numbers to a binary vector with the specified number of bits.

example

binVal = hexToBinaryVector(hexNumber,numberOfBits,bitOrder) converts hexadecimal numbers to a binary vector with the specified number of bits in the specified bit ordering.

Examples

collapse all

binVal = hexToBinaryVector('A1')
binVal =

  1×8 logical array

   1   0   1   0   0   0   0   1
binVal = hexToBinaryVector('0xA')
binVal =

  1×4 logical array

   1   0   1   0
binVal = hexToBinaryVector(['A1';'B1'])
binVal =

  2×8 logical array

   1   0   1   0   0   0   0   1
   1   0   1   1   0   0   0   1
binVal = hexToBinaryVector('A1',12,'MSBFirst')
binVal =

  1×12 logical array

   0   0   0   0   1   0   1   0   0   0   0   1
binVal = hexToBinaryVector({'A1';'B1'},8)
binVal = 

  2×8 logical array

   1   0   1   0   0   0   0   1
   1   0   1   1   0   0   0   1
binVal = hexToBinaryVector('A1', [], 'LSBFirst')
binVal =

  1×8 logical array

   1   0   0   0   0   1   0   1

Input Arguments

collapse all

Hexadecimal number to convert to a binary vector, specified as a character vector or string.

Data Types: char | string

Number of bits to represent the decimal number, specified as a numeric value. This is an optional argument. If you do not specify the number of bits, the number is represented using the minimum number of bits needed.

Bit order for the binary vector representation, specified as a character vector or string. Accepted values are:

  • 'MSBFirst' — The first element of the binary vector is the most significant bit.

  • 'LSBFirst' — The first element of the binary vector is the least significant bit.

Data Types: char | string

Output Arguments

collapse all

Binary value, returned as a logical array of 1s and 0s.

Version History

Introduced in R2012b