Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

decimalToBinaryVector

Convert decimal value to binary vector

Syntax

decimalToBinaryVector(decimalNumber)
decimalToBinaryVector(decimalNumber,numberOfBits)
decimalToBinaryVector(decimalNumber,numberOfBits,bitOrder)
decimalToBinaryVector(decimalNumber,[],bitOrder)

Description

example

decimalToBinaryVector(decimalNumber) converts a positive decimal number to a binary vector, represented using the minimum number of bits.

example

decimalToBinaryVector(decimalNumber,numberOfBits) converts a decimal number to a binary vector with the specified number of bits.

example

decimalToBinaryVector(decimalNumber,numberOfBits,bitOrder) converts a decimal number to a binary vector with the specified number of bits in the specified bit ordering.

decimalToBinaryVector(decimalNumber,[],bitOrder) converts a decimal number to a binary vector with default number of bits in the specified bit ordering.

Examples

collapse all

decimalToBinaryVector(6)
ans =

     1     1     0
decimalToBinaryVector(0:4)
ans =

     0     0     0
     0     0     1
     0     1     0
     0     1     1
     1     0     0
decimalToBinaryVector(6, 8, 'MSBFirst')
ans =

     0     0     0     0     0     1     1     0
decimalToBinaryVector(6, [], 'LSBFirst')
ans =

     0     1     1
decimalToBinaryVector(0:4, 4, 'LSBFirst')
ans =

     0     0     0     0
     1     0     0     0
     0     1     0     0
     1     1     0     0
     0     0     1     0

Input Arguments

collapse all

The number to convert to a binary vector specified as a positive integer scalar.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

The number of bits required to correctly represent the decimal. 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. By default minimum number of bits needed to represent the value is specified, unless you specify a value

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

Introduced in R2012b

Was this topic helpful?