On Wed, Aug 14, 2019 at 03:11:44PM +, berni via Digitalmars-d-learn wrote:
[...]
> but unfortunately this does not work:
>
> >ubyte[] convert_string_pair(string first, string second)
> >{
> >return 0x00 ~ first ~ 0x00 ~ second ~ 0x00;
> >}
>
> The reason is, that this expr
I've got a function which takes two strings and should return
them as a ubyte[] with additional zero bytes in between and
around. This works:
ubyte[] convert_string_pair(string first, string second)
{
auto b = new ubyte[](0);
b ~= 0x00 ~ first ~ 0x00 ~ second ~ 0x00;
On Wednesday, 14 August 2019 at 15:11:44 UTC, berni wrote:
The reason is, that this expression creates a string and not a
ubyte[]...
it should be ok to just cast it in this case.
On Friday, 15 February 2019 at 18:11:11 UTC, Dennis wrote:
Your should report our observation: https://issues.dlang.org
```
void main ()
{
enum A = [0x10203040, 0x50607080]; // shall enum behave like
immutable?
auto B = [0x10203040, 0x50607080];
assert (A == B);
auto p = cast (ubyt
te to int, I'm going from int to ubyte
which should always be possible by multiplying the length by 4,
in my case:
int.sizeof * 2 == ubyte.sizeof * 8 == 8
This happens in case B of my example code, but not in case A.
There the cast goes from 4*2 bytes to 1*2 instead of 1*8 and I
don't get a runtime error.
ment to a
> ubyte:
That's correct. If you want to *transcribe* a ubyte[] to an int[], what
you want is probably something like this:
import std.conv : to;
ubyte[] data = ...;
int[] result = data.map!(b => b.to!int).array;
[...]
> I looked at the spec and
I assumed that casting an int[] to a ubyte[] would keep all bytes
and quadruple the length of the original array. But when the
array is a literal, it keeps the same length but truncates every
int element to a ubyte:
```
import std.stdio;
void main()
{
// enum:
enum litA = [0x10203040,
On Tuesday, May 01, 2018 20:13:41 Dr.No via Digitalmars-d-learn wrote:
> I'm trying to do an optimization here: a hash function which
> expect a ubye[] array as argument, would just work if I cast
> string to ubyte[] but I need to convert it to upper case, so I'd
> like to d
On 05/01/2018 10:13 PM, Dr.No wrote:
I'm trying to do an optimization here: a hash function which expect a
ubye[] array as argument, would just work if I cast string to ubyte[]
but I need to convert it to upper case, so I'd like to do that lazily,
so that the byte is converted to
I'm trying to do an optimization here: a hash function which
expect a ubye[] array as argument, would just work if I cast
string to ubyte[] but I need to convert it to upper case, so I'd
like to do that lazily, so that the byte is converted to its
upper case version soon as it's
On Saturday, 11 November 2017 at 15:48:59 UTC, Mike Parker wrote:
auto s = "hello";
auto bytes = s.representation;
https://dlang.org/phobos/std_string.html#.representation
Thank you for the replay.
Now I know.
aki
On Saturday, 11 November 2017 at 15:48:59 UTC, Mike Parker wrote:
On Saturday, 11 November 2017 at 15:38:18 UTC, aki wrote:
[...]
I don't know about the error you're seeing, but the generic way
to get an array of the underlying data type of a string is via
std.string.representation.
import
On Saturday, 11 November 2017 at 15:48:59 UTC, Mike Parker wrote:
On Saturday, 11 November 2017 at 15:38:18 UTC, aki wrote:
auto bytes = cast(immutable(ubyte)[])s;
Of course, if you need a mutable array you should dup:
auto bytes = cast(ubyte[])s.dup;
Not only "should" but he "must" otherwise
On Saturday, 11 November 2017 at 15:38:18 UTC, aki wrote:
Hello,
This will be trivial question but I cannot figure out
what's wrong. I want to convert string to an array of ubyte.
import std.conv;
void main() {
auto s = "hello";
ubyte[] b = to!(ubyte[])(s);
}
On Saturday, 11 November 2017 at 15:38:18 UTC, aki wrote:
Hello,
This will be trivial question but I cannot figure out
what's wrong. I want to convert string to an array of ubyte.
import std.conv;
void main() {
auto s = "hello";
ubyte[] b = to!(ubyte[])(s);
}
Hello,
This will be trivial question but I cannot figure out
what's wrong. I want to convert string to an array of ubyte.
import std.conv;
void main() {
auto s = "hello";
ubyte[] b = to!(ubyte[])(s);
}
It compiles but cause run time error:
std.conv.ConvExceptio
I really wouldn't advise doing that. SysTime contains a long
which
represents the time in hnsecs since midnight, January 1st, 1
A.D., and that
could be written to a file quite easily. But it also contains a
reference to
a TimeZone object, so what you're doing would just be writing
its address
On Monday, January 12, 2015 13:59:27 Laeeth Isharc via Digitalmars-d-learn
wrote:
> import std.datetime;
> import std.stdio;
> import std.conv;
>
> void main(string[] arg)
> {
> auto a=Clock.currTime();
> auto b=cast(ubyte[])a;
> writefln("%s",b);
> }
>
> how do i get the time as a binary re
V Mon, 12 Jan 2015 13:59:27 +
Laeeth Isharc via Digitalmars-d-learn
napsáno:
> import std.datetime;
> import std.stdio;
> import std.conv;
>
> void main(string[] arg)
> {
> auto a=Clock.currTime();
> auto b=cast(ubyte[])a;
> writefln("%s",b);
> }
>
> how do i get the time
On 1/12/15 8:59 AM, Laeeth Isharc wrote:
import std.datetime;
import std.stdio;
import std.conv;
void main(string[] arg)
{
auto a=Clock.currTime();
auto b=cast(ubyte[])a;
writefln("%s",b);
}
how do i get the time as a binary representation I can write to a file?
You can always
import std.datetime;
import std.stdio;
import std.conv;
void main(string[] arg)
{
auto a=Clock.currTime();
auto b=cast(ubyte[])a;
writefln("%s",b);
}
how do i get the time as a binary representation I can write to a
file?
Thanks.
denizzzka:
I am concerned about the extra allocations of temp arrays. here
is it, or not? compiler optimizes it?
There is one allocation, and usually the D compilers can't
optimize it away.
In my case it does not matter but for the future I would like
to know how it can be implemented wit
On Mon, 29 Oct 2012 19:50:57 +0100
"bearophile" wrote:
> denizzzka:
>
> > I am trying to send to remote host utf8 text with zero byte at
> > end (required by protocol)
>
> What if your UTF8 string coming from D already contains several
> zeros?
>
If you need to send a string with an embedde
On Monday, 29 October 2012 at 18:50:58 UTC, bearophile wrote:
denizzzka:
I am trying to send to remote host utf8 text with zero byte at
end (required by protocol)
What if your UTF8 string coming from D already contains several
zeros?
Incredible situation because it is text-based protocol
denizzzka:
I am trying to send to remote host utf8 text with zero byte at
end (required by protocol)
What if your UTF8 string coming from D already contains several
zeros?
toStringz(s) returns a pointer, so you can't cast a pointer (that
doesn't know the length the buffer it points to) to
On Monday, 29 October 2012 at 17:51:56 UTC, bearophile wrote:
denizzzka:
immutable ubyte[] valueBin = cast(immutable(ubyte[]))
toStringz(s); // s is string type
Error: e2ir: cannot cast toStringz(s) of type immutable(char)*
to type immutable(ubyte[])
One way to do it:
import std.stdio;
v
denizzzka:
immutable ubyte[] valueBin = cast(immutable(ubyte[]))
toStringz(s); // s is string type
Error: e2ir: cannot cast toStringz(s) of type immutable(char)*
to type immutable(ubyte[])
One way to do it:
import std.stdio;
void main() {
string s = "hello";
auto valueBin = cast(i
immutable ubyte[] valueBin = cast(immutable(ubyte[]))
toStringz(s); // s is string type
Error: e2ir: cannot cast toStringz(s) of type immutable(char)* to
type immutable(ubyte[])
On 13/07/12 12:52, Johannes Pfau wrote:
Am Fri, 13 Jul 2012 11:53:07 +0200
schrieb Don Clugston :
On 13/07/12 11:16, Johannes Pfau wrote:
Casting from void[] to ubyte[] is currently not allowed in CTFE. Is
there a special reason for this? I don't see how this cast can be
dangerous?
Am Fri, 13 Jul 2012 11:53:07 +0200
schrieb Don Clugston :
> On 13/07/12 11:16, Johannes Pfau wrote:
> > Casting from void[] to ubyte[] is currently not allowed in CTFE. Is
> > there a special reason for this? I don't see how this cast can be
> > dangerous?
>
>
On 13/07/12 11:16, Johannes Pfau wrote:
Casting from void[] to ubyte[] is currently not allowed in CTFE. Is
there a special reason for this? I don't see how this cast can be
dangerous?
CTFE doesn't allow ANY form of reinterpret cast, apart from
signed<->unsigned. In particul
Casting from void[] to ubyte[] is currently not allowed in CTFE. Is
there a special reason for this? I don't see how this cast can be
dangerous?
I need this for a function which accepts any type and passes it's
binary representation to a function only accepti
On Friday, 22 June 2012 at 09:18:38 UTC, simendsjo wrote:
Bug or by design? (using dmd head)
import std.conv;
void main() {
to!(ubyte[])("");
}
std/array.d(493): Attempting to fetch the front of an empty
array of immutable(char)
[snip]
It is design. With the conversion from
Bug or by design? (using dmd head)
import std.conv;
void main() {
to!(ubyte[])("");
}
std/array.d(493): Attempting to fetch the front of an empty array of
immutable(char)
to(_d_assert_msg+0x45) [0x43700d]
to(@property dchar
std.array.front!(immutable(char
34 matches
Mail list logo