the X_mask (all with "1") are *ok*0b1011001101100110000000000000000
the numbers (sometimes with binary "0" at the end) *not*
obj_only → 0x59B3 → 0b000000000000000101100110110011
obj_sig → (0x59B3<<16) →
test → (0x1<<16) → 0b0000000000000100000000000000000b11111111111111110000000000000000
obj_mask → (((1<<16)-1)<<16) →
buf_only → (1<<10) → 0b0000000000000000000100000000000b1011001101100110000010000000000
buf_sig → 0x59b30000^0x400 →
buf_sig → ((0x59B3<<0)<<16)^(1<<10) →0b1011001101100110000010000000000
buf_mask → (((1<<22)-1)<<10) →0b11111111111111111111110000000000
Hi,
I want to print 32 bit binary numbers (0|1) of *fixed* length 32 for
test but there is a problem, the length is *sometimes* not 32
code:
proc calc {msg str} {
 upvar $msg var
 set var [format %#x [uplevel expr $str]]
 puts [format {1> %-10s → %-15s → %#032b} $msg $str $var]
}
On 31/05/2022 14:24, aotto1968 wrote:
Hi,
I want to print 32 bit binary numbers (0|1) of *fixed* length 32 for
test but there is a problem, the length is *sometimes* not 32
code:
proc calc {msg str} {
  upvar $msg var
  set var [format %#x [uplevel expr $str]]
  puts [format {1> %-10s → %-15s → %#032b} $msg $str $var]
}
I think you want "%#034b" for the format - the field width includes the
"0b".
-Ian
obj_only → 0x59B3 →00000000000000000101100110110011
obj_sig → (0x59B3<<16) →01011001101100110000000000000000
test → (0x1<<16) →00000000000000010000000000000000
obj_mask → (((1<<16)-1)<<16) →11111111111111110000000000000000
buf_only → (1<<10) →00000000000000000000010000000000
buf_sig → 0x59b30000^0x400 →01011001101100110000010000000000
buf_sig → ((0x59B3<<0)<<16)^(1<<10) →01011001101100110000010000000000
buf_mask → (((1<<22)-1)<<10) →11111111111111111111110000000000
test1 → 1504933634 →01011001101100110111011100000010
cfg_only → (((11<<16)<<10)) →00101100000000000000000000000000
cfg_sig → (0x59b30000 ^ ((11<<16)<<10)) →01110101101100110000000000000000
On 31.05.22 14:52, Ian Braithwaite wrote:
On 31/05/2022 14:24, aotto1968 wrote:
Hi,
I want to print 32 bit binary numbers (0|1) of *fixed* length 32 for
test but there is a problem, the length is *sometimes* not 32
code:
proc calc {msg str} {
upvar $msg var
set var [format %#x [uplevel expr $str]]
puts [format {1> %-10s ? %-15s ? %#032b} $msg $str $var]
}
I think you want "%#034b" for the format - the field width includes the
"0b".
-Ian
ok, without "#" the field-width is OK but the error with "#" is still
there. (or is this a feature?)
aotto1968 <aotto1968@t-online.de> wrote:
On 31.05.22 14:52, Ian Braithwaite wrote:
On 31/05/2022 14:24, aotto1968 wrote:
Hi,
I want to print 32 bit binary numbers (0|1) of *fixed* length 32 for
test but there is a problem, the length is *sometimes* not 32
code:
proc calc {msg str} {
  upvar $msg var
  set var [format %#x [uplevel expr $str]]
  puts [format {1> %-10s ? %-15s ? %#032b} $msg $str $var]
}
I think you want "%#034b" for the format - the field width includes the
"0b".
-Ian
ok, without "#" the field-width is OK but the error with "#" is still
there. (or is this a feature?)
The critical portion of Ian's response is this:
"the field width includes the '0b'"
Ian is saying that format counts the 0b prefix as part of the width you specify for the format. So if you want format to add the 0b, you need
to use field widths two characters larger than the value you are
formatting (which is why Ian's example uses 034 above).
Alternately, don't ask format to add the 0b, add it yourself:
format 0b%032b $var
And now the 0b is not counted as part of the "field width" when
formatting.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 307 |
Nodes: | 16 (2 / 14) |
Uptime: | 54:50:02 |
Calls: | 6,914 |
Calls today: | 4 |
Files: | 12,379 |
Messages: | 5,430,460 |