Erroneous stencil example or my mistake?

I’m trying to understand an example that uses the stencil mask, but end up with the wrong numbers. Here’s the example:

For example, it may be useful to draw a convex polyhedra such that
(assuming the stencil bufer is cleared to the binary value 1010):

  1. front-facing polygons that pass the depth test set stencil bit 0
  1. front-facing polygons that fail the depth test zero stencil bit 1
  1. back-facing polygons that pass the depth test set stencil bit 2
  1. back-facing polygons that fail the depth test zero stencil bit 3

This could be accomplished in a single rendering pass using:

[quote]

    glStencilMask(~0);
    glStencilClear(0xA);
    glClear(GL_STENCIL_BUFFER_BIT);

    glDepthMask(0);
    glColorMask(0,0,0,0);
    glDisable(GL_CULL_FACE);
    glEnable(GL_STENCIL_TEST);
    glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT);

    glActiveStencilFaceEXT(GL_BACK);
    glStencilOp(GL_KEEP,      // stencil test fail
                GL_ZERO,      // depth test fail
                GL_REPLACE);  // depth test pass
    glStencilMask(0xC);
    glStencilFunc(GL_ALWAYS, 0x4, ~0);

    glActiveStencilFaceEXT(GL_FRONT);
    glStencilOp(GL_KEEP,      // stencil test fail
                GL_ZERO,      // depth test fail
                GL_REPLACE);  // depth test pass
    glStencilMask(0x3);
    glStencilFunc(GL_ALWAYS, 0x1, ~0);

    renderConvexPolyhedra();

[/QUOTE]

Here are my calculations:

Front Faces

Mask 1100 (0xC)
Ref 0100 (0x4)

RESULTS
Stencil Value 1010 (0xA)
Depth Fail 0010 (0x2)
Depth Pass 0110 (0x6)


Back Faces

Mask 0011 (0x3)
Ref 0001 (0x1)

RESULTS
Stencil Value 0010
Depth Fail 0000 (0x0)
Depth Pass 0001 (0x1)

Stencil Value 0110
Depth Fail 0100 (0x4)
Depth Pass 0101 (0x5)

Did I make a stupid mistake somewhere?

Am I misunderstanding what the glStencilMask does?

If there is a 1 in the mask then the bit is write enabled.
If there is a 0 in the mask then the bit is write protected.

So if I have a mask 1010 and a stencil value of 0011 and I want to replace it with 1000, then the result is 1001, right?

I could still really use some help here. I found the example here: http://oss.sgi.com/projects/ogl-sample/registry/EXT/stencil_two_side.txt
and it would seem that it is incorrect. I just need some confirmation and possibly a way to correct the example.