I wanted to write an application that given a timestamp(text basically) and a public key will generate a merkle hash for the creation of a new genesis block. So I decided to first try and re-create the one from Bitcoin.
Unfortunately, I am failing somewhere. This is my code http://pastebin.com/sVmZgMt8
So, I should be getting this result, which is available on the Genesis Block wiki article.
04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73
However while the text in hexadecimal form is there, there is another problem I am getting. This is the output.
1d00ffff000104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73
The first thing wrong is that the nBits are displayed in an endianness different than the one above, and skimming through the Bitcoin source code a lot I failed to see how and where it was swapped, as the only line is this one
txNew.vin[0].scriptSig = CScript() << 486604799 << CBigNum(4) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
Also, there is an additional 0x04 byte in the Coinbase of the Genesis Block that I am also failing to get, and nowhere did I see it being added OR what it represents.