On Sunday, January 14, 2018 02:41:39 FrankLike via Digitalmars-d-learn wrote: > On Sunday, 14 January 2018 at 02:03:39 UTC, Jonathan M Davis > > wrote: > > Well, I'm not quite sure what you mean, but if you mean that > > Such as byte[] byteData =[0,0,0,8]; > to convert, at last,get the string bit :"100".or get the BitArray.
I'd suggest looking at https://dlang.org/phobos/std_bitmanip.html#bitsSet and https://dlang.org/phobos/std_bitmanip.html#BitArray I'm not sure that either of them does quite what you want, but you may be able to use them to get what you want. Alternatively, you can convert to and from string using a radix with std.conv.to - e.g. assert(to!string(42, 2) == "101010"); assert(to!int("101010", 2) == 42); You have to already have convered the array of ubytes to an integral value to do that, but you can get the base-2 representation of a number that way. And one of these could be used to convert the array of ubytes to an integral: https://dlang.org/phobos/std_bitmanip.html#bigEndianToNative https://dlang.org/phobos/std_bitmanip.html#littleEndianToNative https://dlang.org/phobos/std_bitmanip.html#peek https://dlang.org/phobos/std_bitmanip.html#read The only ways in Phobos that I'm aware of to get a number in binary format as a string would be to use std.conv.to or std.conv.parse with a radix or to use toString on BitArray. So, if that's your ultimate goal, you'll need to figure out how to use one of those to get there. - Jonathan M Davis