x86 machine code on DOS - 14 bytes
I think it doesn't get much shorter than this.
00000000 b4 08 cd 21 34 01 88 c2 b4 02 cd 21 eb f2 |...!4......!..|
This version features advanced interactivity™ - after running it from the command line, it spits out the "inverted" characters as long as you write the input digits (which are not echoed); to exit, just do a Ctrl-C.
Unlike the previous solution, this has some trouble running in DosBox - since DosBox doesn't support Ctrl-C correctly, you are forced to close the DosBox window if you want to exit. In a VM with DOS 6.0, instead, it runs as intended.
NASM source:
org 100h
section .text
start:
mov ah,8
int 21h
xor al,1
mov dl,al
mov ah,2
int 21h
jmp start
Old solution - 27 25 22 bytes
This accepted its input from the command line; runs smoothly as a .COM file in DosBox.
00000000 bb 01 00 b4 02 8a 97 81 00 80 f2 01 cd 21 43 3a |.............!C:|
00000010 1e 80 00 7c f0 c3 |...|..|
NASM input:
org 100h
section .text
start:
mov bx, 1
mov ah, 2
loop:
mov dl, byte[bx+81h]
xor dl, 1
int 21h
inc bx
cmp bl, byte[80h]
jl loop
exit:
ret
char(~(g-'0')+'0')
whereg
holds the stringg='1000'
. – CroCo Oct 28 '15 at 3:50