A simple solution is to place the weight at the north of your node, using the above style option :

```
\documentclass[crop]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\tikzset{mynode/.style={ellipse,minimum height=20pt,minimum width=30pt,draw},}
\begin{tikzpicture}
\draw
(-1,-2) node[mynode] (ini) {ini}
(0,0) node[mynode] (0) {0}
(3,0) node[mynode] (1) {1}
(0.north) node[above] {4}
(1.north) node[above] {6} ;
\draw[-latex]
(ini)->(0) ;
\draw[-latex]
(0)->(1) ;
\end{tikzpicture}
\end{document}
```

which gives the result:

Probably could be done with the the new graph library, but I went for an old fashioned approach, by drawing the nodes first and then determining which nodes should be connected by using the base conversion stuff. No commas between the digits, but that is left as an exercise for the reader :).

```
\documentclass[border=0.125cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\pgfmathsetbasenumberlength{4}
% Take two decimal numbers from 0 - 15, convert them
% to binary and detemine if their nodes should be
% connected.
\def\process#1#2{%
\pgfmathdectobase{\x}{#1}{2}%
\pgfmathdectobase{\y}{#2}{2}%
% Expand the arguments...
\edef\args{\x\y}%
% ...so that the next line produces (for example)
% \Process01000111
\expandafter\Process\args}
% #1#2#3#4 correspond to the bits of the first number
% #5#6#7#8 correspond to the bits of the second number
\def\Process#1#2#3#4#5#6#7#8{%
% Nodes are connected if they differ by exactly one bit.
% So a function is required such that:
%
% sum(f(x_i, y_i)) = 1 for i = 1,...,n
%
% Where n is the number of bits, and x_i and y_i
% are the i'th bits of the numbers x and y.
% The function f must return 1 if the bits are different,
% and zero otherwise.
%
% Consider the function
%
% f(x,y) = (x | y) - (x & y)
%
% For all combinations of x and y:
%
% f(0, 0) = 0
% f(1, 0) = 1
% f(1, 1) = 0
% f(0, 1) = 1
%
% So by summing this function over the bits of x and y
% the nodes will be connected iff the sum is equal to 1
%
% Here I've sort of done the same thing 'by hand', and
% separated the 'or' and 'and' operations as a separate
% function isn't really necessary.
\pgfmathparse{int(or(#1,#5)+or(#2,#6)+or(#3,#7)+or(#4,#8)-and(#1,#5)-and(#2,#6)-and(#3,#7)-and(#4,#8))}%
}
\begin{document}
\begin{tikzpicture}[>=stealth,
% Installed for every node.
every byte/.style={
ellipse,
draw,
font=\sf,
fill=black!50,
text=white
},
% Set some node styles if required
0101/.style={fill=blue!20, text=black},
0001/.style={fill=red!20, text=black}]
\foreach \bytes [count=\y from 0] in {
{0000},
{1000,0100,0010,0001},
{1100,1010,0110,1001,0101,0011},
{1110,1101,1011,0111},
{1111}}
\foreach \byte [count=\x from 0] in \bytes
% Use \byte/.try to install a style if it exists.
\node [x=3cm, y=2cm, every byte/.try, \byte/.try]
% This positioning is a bit of a kludge
at ({\x+abs(2-\y)+(mod(\y, 4)==0)/2}, -\y)
(\byte) {\byte};
% Now go over every combination of numbers to
% to determine if their nodes are connected.
\foreach \x in {0,...,15}{
\foreach \y in {\x,...,15}{
\ifnum\x=\y
\else
\process{\x}{\y}
\ifnum\pgfmathresult=1
\draw [<->] (\x) -- (\y);
\fi
\fi
}
}
\end{tikzpicture}
\end{document}
```

## Best Answer

You are better with the excellent »chemfig« package. It is based on »PGF/TikZ« and offers an easy syntax.

The package manual has the details.