Skip to main content
Added TIO link, corrected byte count, added link to gforth, fixed spelling of "require" and added syntax highlighting
Source Link

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 . ; 

Try it online!

\ 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 ; 

Forth, 131 bytes.

Requres 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 . ; 
\ 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 (gforth), 130 bytes.

Requires 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 . ; 

Try it online!

\ 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 ; 
Made post info a level one heading
Source Link
lyxal
  • 35.6k
  • 2
  • 69
  • 148

Forth, 131 bytes.

Forth, 131 bytes. Requres Requres 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 . ; 

Usage: q 10001011111100010111110001111110 [enter]

Deobfuscated version (or how I would really do it)

\ 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, 131 bytes. Requres 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 . ; 

Usage: q 10001011111100010111110001111110 [enter]

Deobfuscated version (or how I would really do it)

\ 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, 131 bytes.

Requres 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 . ; 

Usage: q 10001011111100010111110001111110 [enter]

Deobfuscated version (or how I would really do it)

\ 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 ; 
Made the short version shorter and the clear version clearer.
Source Link

Forth, 144131 bytes. Requres a Forth that starts in decimal mode, works with gforth.

hex : p . 8 emit ." ." ; : rd rshiftdup ff255 and swap ; : r 8 rshift d ; : q 32 2 base ! word number drop dup ff and swap dup 8d r swap dup 10 r swapr 18drop r decimal p p p . ; 

Usage: q 10001011111100010111110001111110 [enter]

Deobfuscated version (or how I would really do it)

hex\ Forth program to convert a binary IP address to dotted decimal notation.  decimal : binary 2 base ! ; \ Print a quad,Get backspacethe overbinary it'sstring trailingand space,convert printto a dotnumber. : .quadgetbin .32 8binary emitword ."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 ; \: Inputquad a 32 bit8 binarymask string,swap convert; : to3more a number, dropquad thequad quad ;  \ doublePrint precisiona partquad, dup originalbackspace number,over maskit's andtrailing swapspace, \ print the 4a quadsdot. : qdot.quad 32. binary8 wordemit number." drop ." ; \ Print all dup4 ffquads andin swapdecimal. : .4quads dupdecimal 8.quad mask.quad swap .quad . ; \ Get dupbinary 10number, maskchop swap it up into 4 18quads, maskprint decimalin decimal.quad : .quadqdot .quad  getbin quad4 3more drop .4quads ; 

Forth, 144 bytes

hex : p . 8 emit ." ." ; : r rshift ff and ; : q 32 2 base ! word number drop dup ff and swap dup 8 r swap dup 10 r swap 18 r decimal p p p . ; 

Usage: q 10001011111100010111110001111110 [enter]

Deobfuscated version (or how I would really do it)

hex : binary 2 base ! ; \ Print a quad, backspace over it's trailing space, print a dot. : .quad . 8 emit ." ." ; \ Shift and mask the byte we are interested in. : mask rshift ff and ; \ Input a 32 bit binary string, convert to a number, drop the \ double precision part, dup original number, mask and swap, \ print the 4 quads. : qdot 32 binary word number drop  dup ff and swap dup 8 mask swap  dup 10 mask swap  18 mask decimal .quad .quad .quad . ; 

Forth, 131 bytes. Requres 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 . ; 

Usage: q 10001011111100010111110001111110 [enter]

Deobfuscated version (or how I would really do it)

\ 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 ; 
Source Link
Loading