25.9 million results. Wow....
GOOGLE[
^] is your friend and you should visit him often. What you need to do is find a link in the list I've provided which gives you the algorithm and then convert that into the code language of your choice. Happy hunting.