OFFSET
1,2
LINKS
Indranil Ghosh, Table of n, a(n) for n = 1..10000
J. Nelson Raja, P. Jaganathan and S. Domnic, A New Variable-Length Integer Code for Integer Representation and Its Application to Text Compression, Indian Journal of Science and Technology, Vol 8(24), September 2015.
EXAMPLE
For n = 6, The Elias delta code for 6 is "10110" which is 22 in decimal. So, a(6) = 22.
PROG
(Python)
def unary(n):
....return "1"*(n-1)+"0"
def elias_gamma(n):
....if n==1:
........return "1"
....k=int(math.log(n, 2))
....fp=unary(1+k) #fp is the first part
....sp=n-2**(k) #sp is the second part
....nb=k #nb is the number of bits used to store sp in binary
....sp=bin(sp)[2:]
....if len(sp)<nb:
........sp=("0"*(nb-len(sp)))+sp
....return fp+sp
def elias_delta(n):
....if n==1:
........return "1"
....k=int(math.log(n, 2))
....fp=elias_gamma(1+k)#fp is the first part
....sp=n-2**(k) #sp is the second part
....nb=k #nb is the number of bits used to store sp in binary
....sp=bin(sp)[2:]
....if len(sp)<nb:
........sp=("0"*(nb-len(sp)))+sp
....return fp+sp
def a(n):
....return int(elias_delta(n), 2)
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Indranil Ghosh, Jan 18 2017
STATUS
approved