There’s a lot of conflicting advice, both in this thread and on the 'net. The following is what I was always told when hiking in Glacier Park, which is home to both grizzly and black bears (unlike, say, Yosemite) but where the bears are not generally greatly acclimated to humans (again, unlike Yosemite).
You don’t want to wave your arms, yell, and act aggressive. A bear who perceives an imminent threat will attack. You don’t want to lie “face down,” to the extent that implies you should be stretched out, since that gives the bear your legs to gnaw on. You should not run from a bear in close proximity that attacking or imminently to attack you, be it black or grizzly, because it any bear, of either species, can out-run you. And trying to discern whether the bear is trying to (a) eat you; (b) scare you off; © protect its young; or (d) work of some aggression, may sound good in theory, but the reality is that you are unlikely to know why the bear is attacking you until after the attack – assuming you survive.
The actions recommended by the U.S. National Park Service are: If you see a bear and it doesn’t see you or doesn’t appear overly bothered by you, leave the area immediately and quickly, but without running. Do not do anything that the bear might consider threatening, as that may trigger an attack that otherwise would not have taken place. (Bears usually only attack when they are threatened.) If you are nevertheless the victim of the attack, do not try to fight back – you will lose. Roll into a ball, tucking your extremities up as well as you can. Hopefully, once the bear sees you’re not a threat, it will disengage and leave.
The joke about bear bells in grizzly scat is an old one, but bear bells are highly recommended in bear country. Make noise as you go along, because the most common scenario of attack is when a bear is surprised by a hiker (and feels threatened by the sudden appearance and/or proximity). Keep your pack on your back as it will provide extra protection in the highly unlikely event you are mauled.
You can find information on how to deal with bears (at least in Glacier Park) here.
Some of the best land for hiking is not coincidentally the best remaining territory for bears: the U.S. National Parks. So the comments about carrying a great big ol’ gun should also be taken with a grain of salt. For those of us who hike and camp in the U.S. National Parks, it is worth remembering that firearms are prohibited in the all the parks. Regulations vary regarding state lands (and, for that matter, regarding National Forest lands), depending on season and purpose (i.e., you might be allowed to take a rifle onto Forest Service land to hunt game, in the proper season and with the proper permit, but you still might not – probably will not – be allowed to take a pistol for vague purposes of personal defense). So you should check with your local authorities before toting a gun into the back country.