6
$\begingroup$
Table[2^^1*^k,{k,0,10}]

This gives an error, why is that?

Also this BaseForm[2 ** 1*^ #, 16] & /@ Range[10]

What is wrong here?

$\endgroup$
  • $\begingroup$ If you explain the output you expect, someone may be able to help you. $\endgroup$ – mikado Aug 20 '16 at 8:03
  • $\begingroup$ I didn’t think that the output where important, but i try to explain it in the comment to the answer of Mr.Wizard. $\endgroup$ – kafkarudo Aug 21 '16 at 11:50
  • 1
    $\begingroup$ It doesn't work because *^ is not an operator that joins two expressions. It is part of the notation of numbers. This situation is completely equivalent to asking why Table[1k3, {k, 1, 4}] does not work for producing the four numbers {113,123,133,143}. Use an explicit multiplier as in Table[num*base^k, {k, 0, 10}]. $\endgroup$ – Szabolcs Aug 22 '16 at 9:26
8
$\begingroup$

The number entry form base^^digits is only valid for explicit [0-9] digits in the place of both base and digits. You cannot write literal b^^1001 and then attempt to replace b as b^^1001 does not parse to this input form.

Likewise the number entry form m*^exp is only valid for explicit [0-9] digits in the place of both m and exp.

The combination of these entry forms does work, but possibly not in the manner you intend. (One must guess your intent.) For example 2^^1001*^12 inputs 36864, because 1001*^12 is first converted to 1001000000000000 and then 2^^1001000000000000 becomes 36864.


Responding to the comment below, if the combined behavior is what you want you could "force" this evaluation by assembling a String and then converting it to an Expression using ToExpression:

Table[ToExpression[ "2^^1*^" <> ToString[k] ], {k, 0, 10}]
{1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024}

This however makes one wonder why you would not simply write:

2^Range[0, 10]
{1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024}

Or more generally:

Table[2^^1001 * 2^k, {k, 0, 10}]
{9, 18, 36, 72, 144, 288, 576, 1152, 2304, 4608, 9216}

Equivalent to:

 Table[ToExpression["2^^1001*^" <> ToString[k]], {k, 0, 10}]
$\endgroup$
  • $\begingroup$ Sorry if wasn’t clear with my problem. Yes that was exactly the behaviour that i was expecting. I’m working with a digital bus that takes 16bits in binary and only 1 bit at the time is on ( 1 ). So I want a list of 15 numbers 2^^1*^15, 2^^1*^14 ... and convert it to hexadecimal. $\endgroup$ – kafkarudo Aug 21 '16 at 11:46
  • $\begingroup$ @kafkarudo please see my updated answer. $\endgroup$ – Mr.Wizard Aug 21 '16 at 20:17
  • $\begingroup$ Thanks Mr.Wizard, “It’s not the destination, but the journey, that matters” $\endgroup$ – kafkarudo Aug 25 '16 at 9:34
  • $\begingroup$ @kafkarudo You're welcome. :-) $\endgroup$ – Mr.Wizard Aug 25 '16 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.