digitalmars.D.learn - Where can get the Number Convert module?Thanks.
- FrankLike (5/5) Jan 13 2018 Hi,everyone,
- Jonathan M Davis (11/16) Jan 13 2018 Well, I'm not quite sure what you mean, but if you mean that you want to
- FrankLike (5/6) Jan 13 2018 Such as byte[] byteData =[0,0,0,8];
- FrankLike (4/7) Jan 13 2018 Sorry,Such as byte[] byteData =[8,0,0,0];
- Jonathan M Davis (25/30) Jan 13 2018 I'd suggest looking at
- FrankLike (4/9) Jan 13 2018 I get the result "1000" from byte[] byteData =[0,0,0,8];
- FrankLike (3/12) Jan 13 2018 I get the result "1000" from ubyte[] byteData =[0,0,0,8];
- Jonathan M Davis (8/20) Jan 13 2018 Good to hear.
- FrankLike (3/13) Jan 13 2018 Thank you.
Hi,everyone, I need some help on 'Number Convert module' in D,such as byte[] type to BinaryDigit. Where can get the module? Thanks.
Jan 13 2018
On Sunday, January 14, 2018 01:45:37 FrankLike via Digitalmars-d-learn wrote:Hi,everyone, I need some help on 'Number Convert module' in D,such as byte[] type to BinaryDigit. Where can get the module? Thanks.Well, I'm not quite sure what you mean, but if you mean that you want to take a ubyte[] and do something like take arr[0 .. 4] and convert that to int, then you should check out https://dlang.org/phobos/std_bitmanip.html In particular, https://dlang.org/phobos/std_bitmanip.html#bigEndianToNative https://dlang.org/phobos/std_bitmanip.html#peek https://dlang.org/phobos/std_bitmanip.html#read - Jonathan M Davis
Jan 13 2018
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 thatSuch as byte[] byteData =[0,0,0,8]; to convert, at last,get the string bit :"100".or get the BitArray. Thanks.
Jan 13 2018
On Sunday, 14 January 2018 at 02:41:39 UTC, FrankLike wrote:On Sunday, 14 January 2018 at 02:03:39 UTC, Jonathan M Davis wrote:Sorry,Such as byte[] byteData =[8,0,0,0]; to convert, at last,get the string bit :"100".or get the BitArray. Thanks.Well, I'm not quite sure what you mean, but if you mean that
Jan 13 2018
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: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 DavisWell, I'm not quite sure what you mean, but if you mean thatSuch as byte[] byteData =[0,0,0,8]; to convert, at last,get the string bit :"100".or get the BitArray.
Jan 13 2018
On Sunday, 14 January 2018 at 03:09:40 UTC, Jonathan M Davis wrote:On Sunday, January 14, 2018 02:41:39 FrankLike via Digitalmars-d-learn wrote:I get the result "1000" from byte[] byteData =[0,0,0,8]; Thank you very much.[...]I'd suggest looking at [...]
Jan 13 2018
On Sunday, 14 January 2018 at 03:28:28 UTC, FrankLike wrote:On Sunday, 14 January 2018 at 03:09:40 UTC, Jonathan M Davis wrote:I get the result "1000" from ubyte[] byteData =[0,0,0,8]; Thank you very much.On Sunday, January 14, 2018 02:41:39 FrankLike via Digitalmars-d-learn wrote:[...]I'd suggest looking at [...]
Jan 13 2018
On Sunday, January 14, 2018 03:28:28 FrankLike via Digitalmars-d-learn wrote:On Sunday, 14 January 2018 at 03:09:40 UTC, Jonathan M Davis wrote:Good to hear. On a side note, I would point out that you almost certainly want to be using ubyte and not byte. byte is signed, whereas ubyte is unsigned. So, if you want to represent bytes of memory rather than an integral value between 1 and 127, then you want ubyte. - Jonathan M DavisOn Sunday, January 14, 2018 02:41:39 FrankLike via Digitalmars-d-learn wrote:I get the result "1000" from byte[] byteData =[0,0,0,8]; Thank you very much.[...]I'd suggest looking at [...]
Jan 13 2018
On Sunday, 14 January 2018 at 03:49:05 UTC, Jonathan M Davis wrote:Thank you.I get the result "1000" from byte[] byteData =[0,0,0,8]; Thank you very much.Good to hear. On a side note, I would point out that you almost certainly want to be using ubyte and not byte. byte is signed, whereas ubyte is unsigned. So, if you want to represent bytes of memory rather than an integral value between 1 and 127, then you want ubyte. - Jonathan M Davis
Jan 13 2018