Function Repository Resource:

FromNegabinary

Source Notebook

Recover an integer from its negabinary representation

Contributed by: Eric W. Weisstein

ResourceFunction["FromNegabinary"][n]

recovers an integer from its negabinary representation.

Details and Options

Negabinary is a representation in base -2.

Examples

Basic Examples (3) 

Recover 15 from negabinary:

In[1]:=
ResourceFunction["FromNegabinary"][{1, 0, 0, 1, 1}]
Out[1]=

Using ToNegabinary:

In[2]:=
ResourceFunction["FromNegabinary"][
 ResourceFunction["ToNegabinary"][15]]
Out[2]=

See the powers of -2 needed to recover the original integer:

In[3]:=
Table[{1, 0, 0, 1, 1}[[-n]] (-2)^(n - 1), {n, 5}]
Out[3]=
In[4]:=
Plus @@ %
Out[4]=

Scope (1) 

FromNegabinary handles negative numbers:

In[5]:=
ResourceFunction["FromNegabinary"][{1, 1, 1, 1}]
Out[5]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 11 February 2019

Related Resources

License Information