digitalmars.D.learn - How do you get a hexstring from a base10 string -or- from a number?
- Enjoys Math (6/6) Feb 03 2016 I am making a method called:
- Enjoys Math (7/13) Feb 03 2016 body { // is currently:
- Enjoys Math (26/42) Feb 03 2016 One solution: create "string_tools.d":
- H. S. Teoh via Digitalmars-d-learn (8/24) Feb 03 2016 @property string debugIDString() {
- anonymous (3/9) Feb 03 2016 to!string has an optional radix (aka base) parameter:
I am making a method called: property string debugIDString() { in { assert(super.toHash() == this.toHash()); } body { }
Feb 03 2016
On Wednesday, 3 February 2016 at 23:43:45 UTC, Enjoys Math wrote:I am making a method called: property string debugIDString() { in { assert(super.toHash() == this.toHash()); } body { }body { // is currently: return to!string(this.toHash()); } and is returning a base10 string, so how would I return a hex string so I can compare numbers displayed to the debugger addresses in visual D?
Feb 03 2016
On Wednesday, 3 February 2016 at 23:45:15 UTC, Enjoys Math wrote:On Wednesday, 3 February 2016 at 23:43:45 UTC, Enjoys Math wrote:One solution: create "string_tools.d": module string_tools; import std.conv: to; string hexString(int x) { string hex = "0x"; for(uint k=0; k < 8; k++) { int hexDig = (x >> (k << 2)) & 0x0000000F; if (hexDig < 10) { hex ~= to!string(hexDig); } else { string hexDixStr; switch (hexDig) { case 10: hexDigStr = "A"; break; case 11: hexDigStr = "B"; break; case 12: hexDigStr = "C"; break; case 13: hexDigStr = "D"; break; case 14: hexDigStr = "E"; break; case 15: hexDigStr = "F"; break; } hex ~= hexDigStr; } } return hex; }I am making a method called: property string debugIDString() { in { assert(super.toHash() == this.toHash()); } body { }body { // is currently: return to!string(this.toHash()); } and is returning a base10 string, so how would I return a hex string so I can compare numbers displayed to the debugger addresses in visual D?
Feb 03 2016
On Wed, Feb 03, 2016 at 11:45:15PM +0000, Enjoys Math via Digitalmars-d-learn wrote:On Wednesday, 3 February 2016 at 23:43:45 UTC, Enjoys Math wrote:property string debugIDString() { import std.format; return format("%x", this.toHash()); } T -- Study gravitation, it's a field with a lot of potential.I am making a method called: property string debugIDString() { in { assert(super.toHash() == this.toHash()); } body { }body { // is currently: return to!string(this.toHash()); } and is returning a base10 string, so how would I return a hex string so I can compare numbers displayed to the debugger addresses in visual D?
Feb 03 2016
On 04.02.2016 00:45, Enjoys Math wrote:On Wednesday, 3 February 2016 at 23:43:45 UTC, Enjoys Math wrote: body { // is currently: return to!string(this.toHash()); } and is returning a base10 string, so how would I return a hex string so I can compare numbers displayed to the debugger addresses in visual D?to!string has an optional radix (aka base) parameter: return to!string(this.toHash(), 16);
Feb 03 2016