zsh-users
 help / color / mirror / code / Atom feed
* Hexadecimalic question ;)
@ 2011-11-10 17:48 meino.cramer
  2011-11-10 17:55 ` Mikael Magnusson
  2011-11-10 19:44 ` Stephane CHAZELAS
  0 siblings, 2 replies; 3+ messages in thread
From: meino.cramer @ 2011-11-10 17:48 UTC (permalink / raw)
  To: zsh-users

Hi,

I have a string conatining hex digits like this:

    hexdig="b05a02d7d1df3e6993eca90fa00241550dc95ec8e22d9b7194e2549cbd2f0ee37ec802d358d7447e0d78568d6f927ca4695173979e0f46573073cc8a785ac181"

and I have an Array like this

    arr=( T h i s i s a n e x a m p l e ! )  # Could be any othe contents!

Now I want to step through hexdig digit by digit and use every single
digit as an index into arr by interpreting each digit as hexadecimal
digit.

Unfortunately I haven't any succes in doing so...

Thank you very much for any help in advance !

Best regards,
mcc


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Hexadecimalic question ;)
  2011-11-10 17:48 Hexadecimalic question ;) meino.cramer
@ 2011-11-10 17:55 ` Mikael Magnusson
  2011-11-10 19:44 ` Stephane CHAZELAS
  1 sibling, 0 replies; 3+ messages in thread
From: Mikael Magnusson @ 2011-11-10 17:55 UTC (permalink / raw)
  To: meino.cramer; +Cc: zsh-users

On 10 November 2011 18:48,  <meino.cramer@gmx.de> wrote:
> Hi,
>
> I have a string conatining hex digits like this:
>
>    hexdig="b05a02d7d1df3e6993eca90fa00241550dc95ec8e22d9b7194e2549cbd2f0ee37ec802d358d7447e0d78568d6f927ca4695173979e0f46573073cc8a785ac181"
>
> and I have an Array like this
>
>    arr=( T h i s i s a n e x a m p l e ! )  # Could be any othe contents!
>
> Now I want to step through hexdig digit by digit and use every single
> digit as an index into arr by interpreting each digit as hexadecimal
> digit.

% for i in ${(s::)hexdig}; do echo -n $arr[$(( 16#$i + 1 ))]; done; echo
mTsaTilnlhl!seaxxsepaxT!aTTiihssTlpxsepeeiilxmnhxieisixpmli!TeesnepeTilsselniineTlnesaela!xinpaiaxshnsxnxeT!iasnsTnsppeanesapheh

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Hexadecimalic question ;)
  2011-11-10 17:48 Hexadecimalic question ;) meino.cramer
  2011-11-10 17:55 ` Mikael Magnusson
@ 2011-11-10 19:44 ` Stephane CHAZELAS
  1 sibling, 0 replies; 3+ messages in thread
From: Stephane CHAZELAS @ 2011-11-10 19:44 UTC (permalink / raw)
  To: zsh-users

2011-11-10, 18:48(+01), meino.cramer@gmx.de:
> Hi,
>
> I have a string conatining hex digits like this:
>
>     hexdig="b05a02d7d1df3e6993eca90fa00241550dc95ec8e22d9b7194e2549cbd2f0ee37ec802d358d7447e0d78568d6f927ca4695173979e0f46573073cc8a785ac181"
>
> and I have an Array like this
>
>     arr=( T h i s i s a n e x a m p l e ! )  # Could be any othe contents!
>
> Now I want to step through hexdig digit by digit and use every single
> digit as an index into arr by interpreting each digit as hexadecimal
> digit.
>
> Unfortunately I haven't any succes in doing so...
[...]

echo ${hexdig//(#m)?/$arr[1+16#$MATCH]}

also works with:

arr="Thisisanexample!"

-- 
Stephane


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-11-10 20:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-10 17:48 Hexadecimalic question ;) meino.cramer
2011-11-10 17:55 ` Mikael Magnusson
2011-11-10 19:44 ` Stephane CHAZELAS

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).