I'm not a writer, so I can't give advice for how, but for a great example, you should check out the novel The Diamond Age by Neal Stephenson. The protagonist is a young girl who finds a "magic" book that is part fairy tale, part computer science textbook. It seamlessly weaves in allegories for binary arithmetic, Turing machines, and programming.
I wish I could give a more detailed description, but it's been too many years since I read it and online summaries focus on other parts of the novel (there's a lot going on!).