Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fl neg bin mul
#tclsh 8.6 set v1 -10 set v2 -2 proc sign i { set g [expr abs($i)] if { $g == $i } { set s 1 return $s } else { set s 0 return $s } } set sign1 [ sign $v1 ] set sign2 [ sign $v2 ] puts $sign1 puts $sign2 proc dec2bin i { set tcl_precision 4 set list {} set B [expr {int($i) }] set C [expr {$i - $B}] set C [expr {abs($C)}] #puts "$C ----1" set result {} set result1 {} if {$B<0} { set B [expr {abs ($B)}] } else { set sign {} #puts "$B----2" } while {$B > 0} { set result [ expr { $B % 2 } ]$result set B [expr {$B/2}] } while {$C<1} { set result1 [expr {$C*2}] #puts "$result1 " set D [expr {int ($result1) }] #puts "$D" set E [expr {$result1 - $D}] #puts "$E" set C $E lappend list $D set llen [llength $list] #puts "$llen - - - 5" #puts "$list " if {$C==0} { break } } return "$result . $list" } set fn1 [dec2bin $v1] set bf1 [ join $fn1 ""] puts $bf1 set fn2 [dec2bin $v2] set bf2 [ join $fn2 ""] puts $bf2 proc exp i { set a [split $i "."] #puts $a set b [llength [split [lindex $a 1] ""]] return $b } set v1e [exp $bf1] set v2e [exp $bf2] 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 $bf1] set v2m 0b[man $bf2] 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 { [ expr $w & 1] == 0 } { puts even } else { puts odd } } else { puts $mul set w [lindex [ split $mul "."] 0] puts $w if { [ expr $w & 1] == 0 } { puts even } else { puts odd } } set sym {} lappend sym $sign1 lappend sym $sign2 set signs [join $sym ""] puts $signs if { $signs == 00 } { puts $mxb } elseif { $signs == 01 } { set k [ split $mul "" ] puts $k set d {} foreach l $k { lappend d [ expr !$l ] } puts $d set f [ expr 0b[ join $d "" ] + 1 ] set h [dec2bin $f] set m [ split $h "" ] set n [linsert $d $y "."] puts [ join $n "" ] } elseif { $signs == 10 } { set k [ split $mul "" ] puts $k set d {} foreach l $k { lappend d [ expr !$l ] } puts $d set f [ expr 0b[ join $d "" ] + 1 ] set h [dec2bin $f] set m [ split $h "" ] set n [linsert $d $y "."] puts [ join $n "" ] } else { puts $mxb }
run
|
edit
|
history
|
help
0
code to identify whether particular coordinate lies in bbox
XorShift On Tcl
Dec to binary addition
Huffman code size
r
wewew
NISP - Planning ID/Test ID
Working for neg
Add Dec2bin
dssd