Two HEX files from a sketch, what's the difference?

I need a hex-file to give away, but there are two of them. Do I need the bootloader? Does the other without a bootloader run in a new CPU?

The sketch itself gets compiled to a single .hex file. You can export that hex file from recent versions of the IDE by choosing the appropriate menu option.

This .hex file can be run on an Atmel board, and it can be uploaded directly (via ISP) without using a bootloader, or it can be uploaded using a bootloader that was previously written to the chip.

The bootloader serves one purpose - it makes it possible to upload new code over serial.

Note that you can combine a sketch with the bootloader by copy/pasting the contents of the hex file around. They'll open in any decent text editor. The last line (the short one that looks very different from all the others) is the end-of-file marker, so you only want one of those, at the end of the file - (the wikipedia entry on intel hex format is a useful reference for this sort of hex file manipulation)

There are two hex-files generated. I made a test sketch, and I got test.ino.mega.hex and test.ino.with_bootloader.mega.hex files.

Weird. What version of the IDE? This sounds like a change in behavior from 1.6.5r5 (which is what I use, since the later ones are buggy due to arduino builder).

In any event, it sounds like it's generating a second copy of the hex file that has already combined it with the bootloader - in case that's what you need. If the users will be starting with a bootloaded chip (ie, a running Arduino Mega, for example), they don't need the version with the bootloader.

I have the latest 1.6.7

Arduino Builder?

Ah - Arduino Builder is the new build process they introduced in 1.6.6. It was not supposed to have any outwardly visible changes, but, uh....

It broke tons of stuff - and not all of it has been fixed. Some perfectly valid code fails on 1.6.6 and 1.6.7 due to problems with the new build process.

I would still like to know what is the difference between those two HEX file. That is to get a definite answer from someone who knows it.

I am building my own board, there is no USB nor serial bus, only I2C and a couple of IOs. So I don't need a Bootloader.

The difference is pretty clear by the name isn't it? One hex has the bootloader, the other misses the bootloader. If you upload the code via ISP and you want to keep the bootloader you need the version with bootloader. If you don't care about the bootloader you can use the use without.

And it's easy to verify. Just open the hex files and the bootloader hex. You can see the hex with bootloader just has the bootloader hex attached to the end...