Earth gets hit by cosmic rays all the time. Wouldn’t this, or other radiation affect the electrons carrying information within a computer? How do computers deal with this?
It can happen, and depending on the intensity of the scrambling of data, either nothing will happen, or you crash the system, with other random bugs happening in between those extremes.
In the case where nothing happens, which is what you’re mainly asking about, it’s because software designers were clever, and made redundancies. [Hamming Codes](https://en.m.wikipedia.org/wiki/Hamming_code) are used to show when only one bit has been flipped, as would happen in a cosmic ray.
Generally, three ways.
The first one is “suck it up”. This doesn’t happen much any more; but for a long time, computers were big enough that cosmic rays and other random radiation wouldn’t do enough to mess up the computer. And sometimes, a computer gets unlucky and all the other things fail, and this happens (there’s a documented case of this from the speedrunning world).
The second is “shielding”. Put some kind of physical barrier up to block cosmic rays. Not usually popular now, but sometimes it’s necessary.
However, the main way is “error correction”. There are a lot of ways to make sure that getting hit is fixable.
The most basic way to do this is to just do everything three times. If one of them gets messed up, you go with the other two. This is very reliable – you need to take two hits in the same thing before there’s a problem – but it’s also a lot of extra work.
A slightly better way is with “Hamming codes”. In this, you send a block of 2^n bits, with n+1 bits set in a specific way (“parity bits”), and the rest carrying actual data. Each of the parity bits is set to cover half of all the bits in the block (including itself, but no other parity bits) so that that half of the bits have an even number of ‘1’s (or odd – as long as you know which it is); and one parity bit covering all of the bits. By doing this, you can either detect one or two errors in the block; or correct one error in the block (you can’t do both; because you can’t tell the difference between one error and two).
There are a lot of other ways that work in-between those two: Hamming codes are one of the better options if you aren’t very concerned about cosmic rays but want some level of protection; while doing everything in triplicate is very reliable, but at the cost of performance.
If there are no error correction it can affect data
Cosmic radiation does affect circuitry and microprocessors. There have been documented incidents that have shown this. See [Single-event upset](http://en.wikipedia.org/wiki/Single-event_upset) for more information.