I would suggest to follow one of these ways:
You can dig into the datasheet(s) of the mifare Ultralight tags and the NFC controller (PN532?). If you have time - that is a good way to understand the stuff.
Another option is to get the code examples from the open-nfc project.