Binary digits: Difference between revisions
Content added Content deleted
m (→{{header|SequenceL}}: Removing duplicate SequenceL. Webpage timed out ad request submitted twice.) |
(→{{header|Haskell}}: syntax highlighting doesn't support `'` --> use `1` instead) |
||
Line 1,161: | Line 1,161: | ||
-- Implement our own version. |
-- Implement our own version. |
||
toBin1 0 = [] |
|||
toBin1 x = (toBin1 $ x `div` 2) ++ (show $ x `mod` 2) |
|||
printToBin n = putStrLn $ printf "%4d %14s %14s" n (toBin n) ( |
printToBin n = putStrLn $ printf "%4d %14s %14s" n (toBin n) (toBin1 n) |
||
main = do |
main = do |
||
putStrLn $ printf "%4s %14s %14s" "N" "toBin" " |
putStrLn $ printf "%4s %14s %14s" "N" "toBin" "toBin1" |
||
mapM_ printToBin [5, 50, 9000]</lang> |
mapM_ printToBin [5, 50, 9000]</lang> |
||
Sample output:<pre> |
Sample output:<pre> |
||
N toBin |
N toBin toBin1 |
||
5 101 101 |
5 101 101 |
||
50 110010 110010 |
50 110010 110010 |