Numeric access to char[]

Peter Thomassen info at peter-thomassen.de
Wed Aug 23 18:53:28 PDT 2006


<veröffentlicht & per Mail versendet>

Hi!

Regan Heath schrieb am Mittwoch, 23. August 2006 02:06:
> Depends what exactly you're trying to do, perhaps this:
> 
> import std.stdio;
> 
> void main()
> {
> char[] c = "azAZ";
> int val;
> val = (cast(int*)c.ptr)[0..1][0];
> //DEBUG
> //writef("(%02d)%08b",c[0],c[0]);
> //writef(",(%02d)%08b",c[1],c[1]);
> //writef(",(%02d)%08b",c[2],c[2]);
> //writefln(",(%02d)%08b",c[3],c[3]);
> writefln("%032b",val);
> val >>= 1;
> writefln("%032b",val);
> }

Thanks, this is what im looking for! But I don't understand this line:
> val = (cast(int*)c.ptr)[0..1][0];

What does [0..1][0] mean?

> p.s. nobody got the ascii values backward ('A' is 65, 'a' is 97)
> it's nobody's fault really.. nobody is to blame..
> 
> "nobody" I love the nick.. have you read the "Deverry" novels by
> "Katherine Kerr"?
> http://www.math.ttu.edu/~kesinger/deverry/kerr.biblio.html

The oldest example of such pun I know of is Polyphemus who is fooled by this
name in Homer's Odyssey which I read parts of in my Latin lessons at school
(albeit the original is Greek). --> http://en.wikipedia.org/wiki/Polyphemus

Peter



More information about the Digitalmars-d-learn mailing list