Is it a bug or I do not undestand something
Andrey Pleskach via Digitalmars-d-ide
digitalmars-d-ide at puremagic.com
Fri May 23 05:32:44 PDT 2014
Hello everybody
I've started to use D language recently and
I have faced with such problem:
I have such method:
byte[] encodeLong(long value) {
byte buf[10] = 0;
long n = (value << 1) ^ (value >> 63);
int position = 0;
while (n & ~0x7F) {
buf[position++] = cast(byte)((n | 0x80) & 0xFF);
n >>>= 7;
}
buf[position++] = cast(byte)(n);
return buf.dup;
}
somewhere in the other module I'm doing this:
string s = "some string";
byte[] buf = encodeLong(s.length);
writeln(buf);
char[] av = cast(char[])(buf);
writeln(av);
And I get such results:
[48, 0, 0, 0, 0, 0, 0, 0, 0, 0]
0
So the questions why?
BR
Andrey
More information about the Digitalmars-d-ide
mailing list