30/01/2024, 17:57
Code de MenzAgitat
Conversion inverse
tcl
proc octet_formatting {value {SI 1}} {
if { $SI } {
set base 1024
set units {Kio Mio Gio Tio Pio Eio Zio}
} else {
set base 1000
set units {Ko Mo Go To Po Eo Zo}
}
if { $value < $base } { return "${value}o" }
foreach unit $units {
set value [expr {$value / ($base / 1.0)} ]
if { $value < $base } {
return "[format %1.2f $value]$unit"
}
}
}
Conversion inverse
tcl
proc form2oct {formated} {
set usi {kio Mio Gio Tio Pio Eio Zio}
set units {ko Mo Go To Po Eo Zo}
set base 1000
regexp {([0-9\.]+)(\w+)} $formated - s u
if {$u in $usi} {
set units $usi
set base 1024
}
for {set i [lsearch $units $u]} {$i>=0} {incr i -1} {
set s [expr $s * $base]
}
return $s
}