Re: Formatting BaseForm Output
- To: mathgroup at smc.vnet.net
- Subject: [mg39471] Re: Formatting BaseForm Output
- From: Paul Abbott <paul at physics.uwa.edu.au>
- Date: Mon, 17 Feb 2003 18:17:14 -0500 (EST)
- Organization: The University of Western Australia
- References: <b1agg2$pil$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
In article <b1agg2$pil$1 at smc.vnet.net>,
"Ersek, Ted R" <ErsekTR at navair.navy.mil> wrote:
> Evaluate the following in Mathematica
>
> In[1]:=
> BaseForm[3914, 16]
>
> and the output looks like (f4a with 16 for a subscript).
> What if you wanted the output above formatted as one of the following
> 0xf4a, 0x0f4a, 0xF4A, 0x0F4A which are often used by programmers.
Here's a hack using the fact the built-in BaseForm relies on
SubscriptBox:
Unprotect[SubscriptBox];
SubscriptBox[a_, "\"16\""] :=
StringJoin["0x", StringDrop[StringDrop[a, 1], -1]]
Protect[SubscriptBox];
BaseForm[3914, 16]
Cheers,
Paul
--
Paul Abbott Phone: +61 8 9380 2734
School of Physics, M013 Fax: +61 8 9380 1014
The University of Western Australia (CRICOS Provider No 00126G)
35 Stirling Highway
Crawley WA 6009 mailto:paul at physics.uwa.edu.au
AUSTRALIA http://physics.uwa.edu.au/~paul