multiplexer and demultiplexer ic
An analog mux will do this.  It is bidirectional, so the same circuit will work as mux or demux depending on which end is driven.  The classic chip is the CD4051 but more modern parts will have better specs.