Artifacts Associated With Ticket 1824688fffffffff
Ticket change [30ac8f37f3] (rid 93299) by lvirden on 2007-11-02 14:46:56:
- assignee initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
the format function in tcl has conversion specifiers for converting to decimal, octal, and hexadecimal. I'm requesting a conversion specifier for converting to binary. There are times when one has a need, at least during debugging, to take a look at a variable's bit pattern to see what bits are on and off. While one could certainly write tcl code to test each bit and output a 1 or a 0 in response, having a conversion character would allow Tcl to do the right thing. Given that Tcl supports 0bNNN for a built-in base specifier, it would seem natural to support perhaps %b to generate an appropriate string.
- foundin initialized to: "None"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "lvirden"
- subsystem initialized to: "11. Conversions From String"
- title initialized to:
format should have a %b for converting integer to binary
- type initialized to: "RFE"
Ticket change [2b46bdd88d] (rid 118713) by dkf on 2007-11-02 23:06:50:
- subsystem changed to: "16. Commands A-H"
Ticket change [a6b7773238] (rid 98655) by dkf on 2007-12-02 20:14:59:
- assignee changed to: "dkf"
Ticket change [cf5dd6d930] (rid 112963) by mboffey2 on 2008-10-23 06:19:01:
- icomment:
The following patch does what you are after I believe. A slightly more involved question is should [scan] also deal with binary numbers. a. should [scan 0b1010 %b] work as well as [scan 1010 %b] - hex can be optionally prefixed with 0x, octal with 0 but not 0o b. should the %i format work - the man page seems to say that it already does - i The input substring must be an integer. The base (i.e. decimal, binary, octal, or hexadecimal) is determined in the same fashion as described in expr. The integer value is stored in the variable, truncated as required by the size modi- fier value. However, tcl8.6a2 gives - % scan 0x1234 %i 4660 % scan 0b1010 %i 0 % scan 0o1234 %i 0 % scan 01234 %i 668 % scan 1234 %i 1234 Malc. --- tcl8.6a2/generic/tclStringObj.c 2008-04-07 16:23:10.000000000 +0100 +++ tcl8.6a2-binary/generic/tclStringObj.c 2008-10-01 23:00:55.000000000 +0100 @@ -1942,6 +1942,7 @@ goto errorMsg; } case 'd': + case 'b': case 'o': case 'x': case 'X': { @@ -2009,6 +2010,9 @@ if (gotHash) { switch (ch) { + case 'b': + Tcl_AppendToObj(segment, "0b", 2); + break; case 'o': Tcl_AppendToObj(segment, "0", 1); precision--; @@ -2073,6 +2077,7 @@ } case 'u': + case 'b': case 'o': case 'x': case 'X': { @@ -2085,6 +2090,10 @@ if (ch == 'u') { base = 10; } + if (ch == 'b') { + base = 2; + numBits = 1; + } if (ch == 'o') { base = 8; numBits = 3; - login: "mboffey2"
- mimetype: "text/plain"
- username: "mboffey2"
- icomment:
Ticket change [7fece0460c] (rid 97645) by mboffey2 on 2008-10-23 06:22:12:
- icomment:
The following patch does what you are after I believe. A slightly more involved question is should [scan] also deal with binary numbers. a. should [scan 0b1010 %b] work as well as [scan 1010 %b] - hex can be optionally prefixed with 0x, octal with 0 but not 0o b. should the %i format work - the man page seems to say that it already does - i The input substring must be an integer. The base (i.e. decimal, binary, octal, or hexadecimal) is determined in the same fashion as described in expr. The integer value is stored in the variable, truncated as required by the size modi- fier value. However, tcl8.6a2 gives - % scan 0x1234 %i 4660 % scan 0b1010 %i 0 % scan 0o1234 %i 0 % scan 01234 %i 668 % scan 1234 %i 1234 Malc. --- tcl8.6a2/generic/tclStringObj.c 2008-04-07 16:23:10.000000000 +0100 +++ tcl8.6a2-binary/generic/tclStringObj.c 2008-10-01 23:00:55.000000000 +0100 @@ -1942,6 +1942,7 @@ goto errorMsg; } case 'd': + case 'b': case 'o': case 'x': case 'X': { @@ -2009,6 +2010,9 @@ if (gotHash) { switch (ch) { + case 'b': + Tcl_AppendToObj(segment, "0b", 2); + break; case 'o': Tcl_AppendToObj(segment, "0", 1); precision--; @@ -2073,6 +2077,7 @@ } case 'u': + case 'b': case 'o': case 'x': case 'X': { @@ -2085,6 +2090,10 @@ if (ch == 'u') { base = 10; } + if (ch == 'b') { + base = 2; + numBits = 1; + } if (ch == 'o') { base = 8; numBits = 3; - login: "mboffey2"
- mimetype: "text/plain"
- username: "mboffey2"
- icomment:
Ticket change [c247021bca] (rid 111459) by mboffey2 on 2008-10-23 06:29:03:
- icomment:
The following patch does what you are after I believe. A slightly more involved question is should [scan] also deal with binary numbers. a. should [scan 0b1010 %b] work as well as [scan 1010 %b] - hex can be optionally prefixed with 0x, octal with 0 but not 0o b. should the %i format work - the man page seems to say that it already does - i The input substring must be an integer. The base (i.e. decimal, binary, octal, or hexadecimal) is determined in the same fashion as described in expr. The integer value is stored in the variable, truncated as required by the size modi- fier value. However, tcl8.6a2 gives - % scan 0x1234 %i 4660 % scan 0b1010 %i 0 % scan 0o1234 %i 0 % scan 01234 %i 668 % scan 1234 %i 1234 Malc. --- tcl8.6a2/generic/tclStringObj.c 2008-04-07 16:23:10.000000000 +0100 +++ tcl8.6a2-binary/generic/tclStringObj.c 2008-10-01 23:00:55.000000000 +0100 @@ -1942,6 +1942,7 @@ goto errorMsg; } case 'd': + case 'b': case 'o': case 'x': case 'X': { @@ -2009,6 +2010,9 @@ if (gotHash) { switch (ch) { + case 'b': + Tcl_AppendToObj(segment, "0b", 2); + break; case 'o': Tcl_AppendToObj(segment, "0", 1); precision--; @@ -2073,6 +2077,7 @@ } case 'u': + case 'b': case 'o': case 'x': case 'X': { @@ -2085,6 +2090,10 @@ if (ch == 'u') { base = 10; } + if (ch == 'b') { + base = 2; + numBits = 1; + } if (ch == 'o') { base = 8; numBits = 3; - login: "mboffey2"
- mimetype: "text/plain"
- username: "mboffey2"
- icomment:
Ticket change [5232badc84] (rid 126269) by dkf on 2009-07-13 01:31:01:
- closedate changed to: "2009-07-12T18:31:01"
- closer changed to: "dkf"
- icomment:
allow_comments - 1 This feature is part of Tcl 8.6: % format %b 123 1111011 % scan 1111011 %b 123 % info patch 8.6b1.1
- login: "dkf"
- mimetype: "text/plain"
- resolution changed to: "Out of Date"
- status changed to: "Closed"
- username: "dkf"