this pdf gives a clear explanation of how transistors works as switches.