zsh-users
 help / color / mirror / code / Atom feed
* Are there "binary" variables?
@ 2006-06-03  0:21 Johann 'Myrkraverk' Oskarsson
  2006-06-03  2:39 ` Philippe Troin
  2006-06-03  5:51 ` Bart Schaefer
  0 siblings, 2 replies; 4+ messages in thread
From: Johann 'Myrkraverk' Oskarsson @ 2006-06-03  0:21 UTC (permalink / raw)
  To: ZSH Users

Hi everyone,

Is there a way to work with binary data in zsh?  That is, more
specifically, is there a way to compare ^E to 5 and get true?  Or
convert a character (say, ^E again) to its integer representation?


Thank you,

Johann

-- 
johann myrkraverk com (you know the drill with the @ and .)
I classify Outlook mail as spam, please use something else for
private messages.


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

* Re: Are there "binary" variables?
  2006-06-03  0:21 Are there "binary" variables? Johann 'Myrkraverk' Oskarsson
@ 2006-06-03  2:39 ` Philippe Troin
  2006-06-03  2:41   ` Philippe Troin
  2006-06-03  5:51 ` Bart Schaefer
  1 sibling, 1 reply; 4+ messages in thread
From: Philippe Troin @ 2006-06-03  2:39 UTC (permalink / raw)
  To: Johann 'Myrkraverk' Oskarsson; +Cc: ZSH Users

"Johann 'Myrkraverk' Oskarsson" <johann@myrkraverk.com> writes:

> Is there a way to work with binary data in zsh?  That is, more
> specifically, is there a way to compare ^E to 5 and get true?  Or
> convert a character (say, ^E again) to its integer representation?

Zsh's parameters are 8-bits clean.

You could do the above with:

typeset -A asc
for i in {0..255}; do asc[$(print "\\$(([##8]$i))")]=$i;done
var=$'\0\1\2\3'
for i in $#var; do print "$i: $asc[$var[$i]]"; done

Phil.


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

* Re: Are there "binary" variables?
  2006-06-03  2:39 ` Philippe Troin
@ 2006-06-03  2:41   ` Philippe Troin
  0 siblings, 0 replies; 4+ messages in thread
From: Philippe Troin @ 2006-06-03  2:41 UTC (permalink / raw)
  To: Johann 'Myrkraverk' Oskarsson; +Cc: ZSH Users

Philippe Troin <phil@fifi.org> writes:

> "Johann 'Myrkraverk' Oskarsson" <johann@myrkraverk.com> writes:
> 
> > Is there a way to work with binary data in zsh?  That is, more
> > specifically, is there a way to compare ^E to 5 and get true?  Or
> > convert a character (say, ^E again) to its integer representation?
> 
> Zsh's parameters are 8-bits clean.
> 
> You could do the above with:
> 
> typeset -A asc
> for i in {0..255}; do asc[$(print "\\$(([##8]$i))")]=$i;done
> var=$'\0\1\2\3'
> for i in $#var; do print "$i: $asc[$var[$i]]"; done

Actually, the last line should read:

for i in {1..$#var}; do print "$i: $asc[$var[$i]]"; done

Phil.


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

* Re: Are there "binary" variables?
  2006-06-03  0:21 Are there "binary" variables? Johann 'Myrkraverk' Oskarsson
  2006-06-03  2:39 ` Philippe Troin
@ 2006-06-03  5:51 ` Bart Schaefer
  1 sibling, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2006-06-03  5:51 UTC (permalink / raw)
  To: ZSH Users

On Jun 3, 12:21am, Johann 'Myrkraverk' Oskarsson wrote:
}
} specifically, is there a way to compare ^E to 5 and get true?

In the manual under "Arithmetic Evaluation", a few pages down:

 An expression of the form `##X' where X is any character sequence such
 as `a', `^A', or `\M-\C-x' gives the ASCII value of this character and
 an expression of the form `#FOO' gives the ASCII value of the first
 character of the value of the parameter FOO.

zsh% print $((##\C-e))
5
zsh% ((##\C-e == 5)) && print It is 5 || print It is not 5
It is 5
zsh% 

In the manual under "Quoting":

 A string enclosed between "$'" and "'" is processed the same way as the
 string arguments of the print builtin, and the resulting string is
 considered to be entirely quoted.

zsh% print $'\5' | cat -v
^E
zsh% ctrlE=$'\5'
zsh% print $((#ctrlE))
5
zsh% 


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

end of thread, other threads:[~2006-06-03  5:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-03  0:21 Are there "binary" variables? Johann 'Myrkraverk' Oskarsson
2006-06-03  2:39 ` Philippe Troin
2006-06-03  2:41   ` Philippe Troin
2006-06-03  5:51 ` Bart Schaefer

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).