Horizons of a bachelor degree in chemistry
You would need certain prerequisite courses to get the master's degree in a different field.  For example, Boston University explains:

The Master of Science (MS) in Computer Science program is intended for computer professionals and for people who intend to move into the computer field from other areas of study (emphasis added).

So yes, you can come from a different background.

Applicants to the program are required to have a baccalaureate degree from a regionally accredited institution and proficiency in the areas covered by the following courses:
◾MET CS 201 Introduction to Programming
◾MET CS 231 Programming with C++ or MET CS 232 Programming with Java
◾MET CS 248 Discrete Mathematics
◾MET CS 341 Data Structures with C++ or MET CS 342 Data Structures with Java
◾MET CS 472 Computer Architecture

So it would be fine to switch to physics, biology, biophysics, or many other programs as long as you have the right prerequisite courses.
However, some schools only accept people wanting a PhD, and give a master's degree along the way, which you get to keep if you don't finish the PhD.