512 and 1024 are both less than 32767 so they are both treated as 'int'. The multiply causes an integer overflow leaving a result of 0. That 0 is then converted to 'unsigned long int'.
To have the math done in unsigned long int, use unsigned long int constants:
unsigned long int k = 512ul * 1024ul;
Note: The arguments to the multiply will have the 'usual conversions' applied. You only need one of the two to be 'unsigned long int' for the other to be converted to 'unsigned long int' before the multiply.