Behavior of electron beams under magnetic compression