digitalmars.D.ide - Is it a bug or I do not undestand something
- Andrey Pleskach (27/27) May 23 2014 Hello everybody
- Andrey Pleskach (3/30) May 23 2014 Oops I get it ... It works correctly.
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
May 23 2014
Oops I get it ... It works correctly. Sorry for such stupid question :) On Friday, 23 May 2014 at 12:32:46 UTC, Andrey Pleskach wrote: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
May 23 2014