Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Perfect bin mul eo float
#tclsh 8.6 set v1 101.110 set v2 011.101 proc exp i { set a [split $i "."] #puts $a set b [llength [split [lindex $a 1] ""]] return $b } set v1e [exp $v1] set v2e [exp $v2] puts $v1e puts $v2e set EXP [expr $v1e + $v2e] puts $EXP proc man i { set a [split $i "."] return [join $a ""] } set v1m 0b[man $v1] set v2m 0b[man $v2] #set man1 0b$v1m #set man2 0b$v2m puts $v1m puts $v2m set sum 0b0 while { $v2m != 0b0 } { set sum [expr $sum + $v1m] set v2m [expr $v2m - 1] } puts $sum proc dec2bin i { set res {} while {$i>0} { set res [expr {$i%2}]$res set i [expr {$i/2}] } if {$res == {}} {set res 0} return $res } set mul [dec2bin $sum] puts $mul if { $EXP != 0 } { set z [split $mul ""] puts $z set y [expr [llength $z] - $EXP] puts $y set x [linsert $z $y "."] puts $x set mxb [join $x ""] puts $mxb set w [lindex [ split $mxb "."] 0] puts $w if { $w & 1 == 0 } { puts even } else { puts odd } } else { puts $mul }
run
|
edit
|
history
|
help
0
Different factorial implementations
Dec to binary addition
Longest common subsequence
Trail
r
a
1
NISP - Wheel Movements 0.1
XorShift On Tcl
2