Decimal floating point number to binary: Difference between revisions

Added Sidef
m (added whitespace before the TOC (table of contents), added a ;Task: (bold) header, corrected a misspelling.)
(Added Sidef)
Line 1,026:
-23.34375 => -10111.01011 => -23.34375
-11.90625 => -1011.11101 => -11.90625
</pre>
 
=={{header|Sidef}}==
<lang ruby>func dec2bin(String n) {
Num(Num(n, 10).base(2), 10)
}
 
func bin2dec(String n) {
Num(Num(n, 10).base(10), 2)
}
 
with("23.34375") { |s| say (" #{s} => ", dec2bin(s)) }
with("1011.11101") { |s| say ( "#{s} => ", bin2dec(s)) }</lang>
{{out}}
<pre>
23.34375 => 10111.01011
1011.11101 => 11.90625
</pre>
 
2,747

edits