Dec to bin

Revision as of 11:38, 18 July 2018 by Rmmateri (talk | contribs)
Jump to navigation Jump to search
Converts a decimal number to a binary number in a similar way to the dec2bin function in MATLAB.

Other toolboxes required none
Function category Helper functions
This is a helper function that only exists to aid other functions in QETLAB. If you are an end-user of QETLAB, you likely will never have a reason to use this function.

dec_to_bin is a function that takes a decimal number as input and converts it to a vector representing the binary form of the number with the MSB to the right.


  • BIN = dec_to_bin(DEC)

Argument descriptions

  • DEC: The decimal number to be converted to a vector representing the binary form of DEC. This must be a non-negative integer.


Some basic examples of how dec_to_bin works.

>> dec_to_bin(5)

ans =

     1     0     1

>> dec_to_bin(6)

ans =

     0     1     1


This function is only meant to simplify code within other functions without the need to install the communications package of MATLAB or Octave-Forge.

Source code

Click on "expand" to the right to view the MATLAB source code for this function.