Decimal floating point number to binary: Difference between revisions
Decimal floating point number to binary (view source)
Revision as of 19:25, 24 September 2016
, 7 years agoAdded 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>
|