www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - String to binary conversion

reply "clearion" <user dlangcentre.org> writes:
I would like to write binary data to a file for an ancillary hash
table operation and then read it back using stream.rawRead(). How
would I go about converting a string to binary in D. I would
prefer not to use any third party libraries if I can. Thank You
Sep 03 2014
next sibling parent reply ketmar via Digitalmars-d <digitalmars-d puremagic.com> writes:
crossposting annoys people and decreases your chances to get the
answer.
Sep 03 2014
parent reply "clearion" <user dlangcentre.org> writes:
On Wednesday, 3 September 2014 at 12:43:01 UTC, ketmar via 
Digitalmars-d wrote:
 crossposting annoys people and decreases your chances to get the
 answer.
maybe it was an accident as I am new to this forum
Sep 03 2014
parent reply ketmar via Digitalmars-d <digitalmars-d puremagic.com> writes:
On Wed, 03 Sep 2014 12:44:29 +0000
clearion via Digitalmars-d <digitalmars-d puremagic.com> wrote:

 maybe it was an accident as I am new to this forum
it's impossible to accidentally cross-post to "general", "announce" and "stackoverflow".
Sep 03 2014
next sibling parent reply "clearion" <user dlangcentre.org> writes:
On Wednesday, 3 September 2014 at 12:49:22 UTC, ketmar via 
Digitalmars-d wrote:
 On Wed, 03 Sep 2014 12:44:29 +0000
 clearion via Digitalmars-d <digitalmars-d puremagic.com> wrote:

 maybe it was an accident as I am new to this forum
it's impossible to accidentally cross-post to "general", "announce" and "stackoverflow".
I accidentally posted to announce, then immediately posted to general. Stackoverflow has nothing to do with this forum as I have my own presence there. You are expending alot of energy being critical rather than trying to help
Sep 03 2014
parent "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Wednesday, 3 September 2014 at 12:52:21 UTC, clearion wrote:
 On Wednesday, 3 September 2014 at 12:49:22 UTC, ketmar via 
 Digitalmars-d wrote:
 On Wed, 03 Sep 2014 12:44:29 +0000
 clearion via Digitalmars-d <digitalmars-d puremagic.com> wrote:

 maybe it was an accident as I am new to this forum
it's impossible to accidentally cross-post to "general", "announce" and "stackoverflow".
I accidentally posted to announce, then immediately posted to general. Stackoverflow has nothing to do with this forum as I have my own presence there. You are expending alot of energy being critical rather than trying to help
There is more overlap between these forums and Stack Overflow than you might think. It's unlikely that you'll get a D-related answer on Stack Overflow from someone who is not a regular on these forums. However, digitalmars.D.learn has much more activity than Stack Overflow. Considering that you are more likely to get an answer there, I find it ironic that you've posted your question everywhere EXCEPT the place where you'd most likely get an answer, and then get upset when people point that out.
Sep 03 2014
prev sibling parent reply "Gary Willoughby" <dev nomad.so> writes:
On Wednesday, 3 September 2014 at 12:43:01 UTC, ketmar via 
Digitalmars-d wrote:
 crossposting annoys people and decreases your chances to get the
 answer.
 it's impossible to accidentally cross-post to "general", 
 "announce" and
 "stackoverflow".
Please can we politely direct newcomers to D.learn with a welcome instead of chewing them out. These people are probably unfamiliar with these newsgroups.
Sep 03 2014
parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 09/03/2014 10:36 AM, Gary Willoughby wrote:
 On Wednesday, 3 September 2014 at 12:43:01 UTC, ketmar via Digitalmars-d
 wrote:
 crossposting annoys people and decreases your chances to get the
 answer.
 it's impossible to accidentally cross-post to "general", "announce" and
 "stackoverflow".
Please can we politely direct newcomers to D.learn with a welcome instead of chewing them out. These people are probably unfamiliar with these newsgroups.
Agreed. :) To Vladimir: Can we move digitalmars.D.learn to the top of the forums at forum.dlang.org? I would even put it in its separate area on that page with larger font, etc. :) Also, I've just noticed that "Questions about learning D" sounds a little off because it sounds as if the questions should be like "how can I learn D". :) How about something like "Questions when learning D". Thank you, Ali
Sep 03 2014
next sibling parent Philippe Sigaud via Digitalmars-d <digitalmars-d puremagic.com> writes:
On Wed, Sep 3, 2014 at 7:59 PM, Ali Çehreli <digitalmars-d puremagic.com>
wrote:

 Also, I've just noticed that "Questions about learning D" sounds a little
 off because it sounds as if the questions should be like "how can I learn
 D". :) How about something like "Questions when learning D".
Or even: "Learning D"
Sep 03 2014
prev sibling next sibling parent reply "HeiHon" <sorry nomail.com> writes:
 Can we move digitalmars.D.learn to the top of the forums at 
 forum.dlang.org? I would even put it in its separate area on 
 that page with larger font, etc. :)
+1 Given that it seems quite common for newbies to not ask their first questions in D.learn.
 Also, I've just noticed that "Questions about learning D" 
 sounds a little off because it sounds as if the questions 
 should be like "how can I learn D". :) How about something like 
 "Questions when learning D".
Or "Here you find answers to your questions when/while learning D" (Not a native speaker here)
Sep 04 2014
parent "monarch_dodra" <monarchdodra gmail.com> writes:
On Thursday, 4 September 2014 at 14:43:03 UTC, HeiHon wrote:
 Can we move digitalmars.D.learn to the top of the forums at 
 forum.dlang.org? I would even put it in its separate area on 
 that page with larger font, etc. :)
+1 Given that it seems quite common for newbies to not ask their first questions in D.learn.
Not *that* common. Heck, I find it's rare compared to a lot of other forums. I think the current setup is fine.
Sep 04 2014
prev sibling next sibling parent Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
On 9/3/2014 1:59 PM, Ali Çehreli wrote:
 To Vladimir:

 Can we move digitalmars.D.learn to the top of the forums at
 forum.dlang.org? I would even put it in its separate area on that page
 with larger font, etc. :)

 Also, I've just noticed that "Questions about learning D" sounds a
 little off because it sounds as if the questions should be like "how can
 I learn D". :) How about something like "Questions when learning D".
I'd suggest a box, with a colored background, near the top saying: Need help using D? Ask in <a href="...">D.learn</a>!
Sep 05 2014
prev sibling parent reply "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Wednesday, 3 September 2014 at 17:59:24 UTC, Ali Çehreli wrote:
 Can we move digitalmars.D.learn to the top of the forums at 
 forum.dlang.org?
OK, done. But I think this is the fourth time I'm changing the layout. Hopefully this will be the last.
 I would even put it in its separate area on that page with 
 larger font, etc. :)
Let's see how far this gets us before messing with font sizes and colors.
 Also, I've just noticed that "Questions about learning D" 
 sounds a little off because it sounds as if the questions 
 should be like "how can I learn D". :) How about something like 
 "Questions when learning D".
The descriptions are from the DigitalMars news server. Do you think I should change the local copy on the forum? It will no longer be the same as the actual newsgroup description.
Sep 07 2014
next sibling parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 09/07/2014 02:45 PM, Vladimir Panteleev wrote:
 On Wednesday, 3 September 2014 at 17:59:24 UTC, Ali Çehreli wrote:
 Can we move digitalmars.D.learn to the top of the forums at
 forum.dlang.org?
OK, done.
Thank you! :) This solves the issue. Ali
Sep 07 2014
prev sibling parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 9/7/14, 2:45 PM, Vladimir Panteleev wrote:
 On Wednesday, 3 September 2014 at 17:59:24 UTC, Ali Çehreli wrote:
 Can we move digitalmars.D.learn to the top of the forums at
 forum.dlang.org?
OK, done. But I think this is the fourth time I'm changing the layout. Hopefully this will be the last.
BTW all of the forum should go on our repo on github. -- Andrei
Sep 07 2014
prev sibling next sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
You could just write the string length then the data to the file 
using the .length and index things on string.

file.write(mystr.length);
file.write(mystr); // should automatically write out all the 
bytes of the string
Sep 03 2014
parent "clearion" <user dlangcentre.org> writes:
On Wednesday, 3 September 2014 at 12:47:06 UTC, Adam D. Ruppe
wrote:
 You could just write the string length then the data to the 
 file using the .length and index things on string.

 file.write(mystr.length);
 file.write(mystr); // should automatically write out all the 
 bytes of the string
Thanks Mr. Ruppe. I'll give it a try
Sep 03 2014
prev sibling parent "Colin" <grogan.colin gmail.com> writes:
On Wednesday, 3 September 2014 at 12:33:49 UTC, clearion wrote:
 I would like to write binary data to a file for an ancillary 
 hash
 table operation and then read it back using stream.rawRead(). 
 How
 would I go about converting a string to binary in D. I would
 prefer not to use any third party libraries if I can. Thank You
I think this: void main(){ string str = "Test string"; auto file = File("output.txt", "w"); auto bin = cast(ubyte[])str; foreach(b; bin){ file.writef("%b", b); } file.close(); } will do it? This is untested though....
Sep 03 2014