Name

number_tobary — Decompose a number into arbitrary basis.

Calling Sequence

   digits = number_tobary ( n )
   digits = number_tobary ( n , basis )
   digits = number_tobary ( n , basis , order )
   digits = number_tobary ( n , basis , order , p )
   
   

Parameters

n :

a 1x1 matrix of floating point integers, the integer to decompose, must be positive

basis :

a 1x1 matrix of floating point integers, the basis, must be positive, (default basis=2)

order :

a 1x1 matrix of strings, the order (default order="littleendian")

p :

a 1x1 matrix of floating point integers, the number of digits on output (default p=0)

digits :

a p-by-1 matrix of floating point integers, the digits.

Description

Returns a column matrix of digits of the decomposition of n in base b, i.e. decompose n as

n = d(1) b^(p-1) + d(2) b^(p-2) + ... + d(p) b^0.

This order is little endian order since the last digit is associated with b^0. If "bigendian" order is chosen, returns the digits d so that

n = d(1) b^0 + d(2) b^1 + ... + d(p) b^(p-1),

i.e. the last digit is associated with b^(p-1).

If p=0, returns the least possible number of digits. If p is a positive integer, returns p digits. If the integer cannot be stored in p digits, generates an error. If the integer is larger than p digits, pad with zeros.

Examples

number_tobary (4,2) // [1 0 0]
number_tobary (4,2,"bigendian") // [0 0 1]
number_tobary (4,2,"littleendian",8) // [0,0,0,0,0,1,0,0]

   

Bibliography

Monte-Carlo methods in Financial Engineering, Paul Glasserman

Authors

Copyright (C) 2008-2009 - INRIA - Michael Baudin
Copyright (C) 2010 - DIGITEO - Michael Baudin