Inside the Leather Owners Case that came with the car (usually in the glovebox and includes Users Manual) there should be a booklet on the Radio/Anti-Theft System. In the fold out back cover of this book there are 2 Cards (one duplicate) that will have the Factory Set Code to be used for your radio. You are prompted to enter this code if the radio has been removed from the vehicle (Stolen) or if the battery died/was disconnected and the radio lost voltage.
If you do not have the original cards that came with your car, you can remove the radio and pull the serial/part numbers off the back of it. If you take those numbers to a BMW Dealership along with proof of ownership of the vehicle, many will provide you the factory code for free.
If you are not comfortable removing the radio, the dealership will also do that for you (labor charges will be incurred however for removal/replacing the stereo).
Hope that helps!
J.D. Rowe, January 2009