program demo(input,output);

const
   hexdigits = 8; (*  hexdigits = bits/integer DIV 4  *)

type
   hexint = packed array [1..hexdigits] of char;

procedure hexify(val:integer;var res:hexint);

var
   tmp   : hexint;
   v,d,i : integer;
   neg   : boolean;

begin
   neg:=false;
   v:=val;
   if v<0 then begin
      v:=v+maxint;
      v:=v+1;
      neg:=true;
   end;
   for i:=1 to hexdigits do begin
      d:=v mod 16;
      if neg and (i=hexdigits) then d:=d+8;
      if d<=10 then d:=d+48 else d:=d+55;
      res[hexdigits-i+1]:=chr(d);
      v:=v div 16;
   end;
end;

procedure doit(i:integer);

var
   r : hexint;

begin
   hexify(i,r);
   writeln(r)
end;

begin
   doit(1);
   doit(0);
   doit(-1);
   doit(123);
   doit(-123);
end.
