An optical analog-to-digital converter based on nonlinear resonant cavities in photonic crystals