RM had some excellent advice:
If it's a black bear- DO NOT play dead. They are scavengers and will continue to come after you, even if you don't seem to pose a threat. You want to wave your arms in the air and make as much noise as possible. They will run if they think that you are a threat. They will try to eat you if they think that you are a free snack. You are more likely to encounter a black bear than a brown or grizzly.
If it's a brown bear- your best bet is to play dead. They will fight back when provoked or threatened and generally have no interest in "dead" prey.
All of these rules are thrown out the window if you come between a sow and a cub. You are more or less just fucked. Your best chance of survival is to roll into a ball and cover your head and neck with your arms.
One of our resident experts, Dan Moore (owner of EverGreen Escapes) also had some smart suggestions:
It is true that when you are being attacked by a bear you need to play dead. This proves you are not a threat. If you are continued to be bitten though, it means the bear is thinking you are food. That is when you fight your ass off.
For grizzlies, pepper spray is required gear to carry with you. It has been proven more effective then guns.
Prevention is the best medicine. Don't attract bears and know how to avoid them. Learn what bear signs look like (tracks, scat, fur, etc). I've hiked and lived in bear country for many years. I've seen black bears in my camp only a couple times. These techniques have worked for me and thankfully I've not ever been in danger. The odds are in your favor. Just be smart.
Read even more about what to do if a bear attacks here! Questionland—it can save your fuckin' ass.