Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,16 @@
|
|||
package require Tcl 8.6; # For easy scanning of binary
|
||||
|
||||
# The strings to parse
|
||||
set dec1 "0123459"
|
||||
set hex2 "abcf123"
|
||||
set oct3 "7651"
|
||||
set bin4 "101011001"
|
||||
|
||||
# Parse the numbers
|
||||
scan $dec1 "%d" v1
|
||||
scan $hex2 "%x" v2
|
||||
scan $oct3 "%o" v3
|
||||
scan $bin4 "%b" v4; # Only 8.6-specific operation; others work in all versions
|
||||
|
||||
# Print out what happened
|
||||
puts "$dec1->$v1 $hex2->$v2 $oct3->$v3 $bin4->$v4"
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
proc scanbase {str base} {
|
||||
set res 0
|
||||
set digits {0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z}
|
||||
foreach char [split [string tolower $str] ""] {
|
||||
set value [lsearch [lrange $digits 0 [expr {$base - 1}]] $char]
|
||||
if {$value < 0} {error "bad digit $char"}
|
||||
set res [expr {$res*$base + $value}]
|
||||
}
|
||||
return $res
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue