ForthForth (gforth), 131130 bytes.
RequresRequires a Forth that starts in decimal mode, works with gforth.
: p . 8 emit ." ." ; : d dup 255 and swap ; : r 8 rshift d ; : q 32 2 base ! word number drop d r r r drop decimal p p p . ; : p . 8 emit ." ." ; : d dup 255 and swap ; : r 8 rshift d ; : q 32 2 base ! word number drop d r r r drop decimal p p p . ; \ Forth program to convert a binary IP address to dotted decimal notation. decimal : binary 2 base ! ; \ Get the binary string and convert to a number. : getbin 32 binary word number drop ; \ Shift and mask the byte we are interested in. Put all 4 on the stack. hex : mask rshift dup ff and ; : quad4 dup ff and swap ; : quad 8 mask swap ; : 3more quad quad quad ; \ Print a quad, backspace over it's trailing space, print a dot. : .quad . 8 emit ." ." ; \ Print all 4 quads in decimal. : .4quads decimal .quad .quad .quad . ; \ Get binary number, chop it up into 4 quads, print in decimal. : qdot getbin quad4 3more drop .4quads ; \ Forth program to convert a binary IP address to dotted decimal notation. decimal : binary 2 base ! ; \ Get the binary string and convert to a number. : getbin 32 binary word number drop ; \ Shift and mask the byte we are interested in. Put all 4 on the stack. hex : mask rshift dup ff and ; : quad4 dup ff and swap ; : quad 8 mask swap ; : 3more quad quad quad ; \ Print a quad, backspace over it's trailing space, print a dot. : .quad . 8 emit ." ." ; \ Print all 4 quads in decimal. : .4quads decimal .quad .quad .quad . ; \ Get binary number, chop it up into 4 quads, print in decimal. : qdot getbin quad4 3more drop .4quads ;