Is this wrong?

Is it ok to give your number to a guy if you're in a relationship? I just moved into college and this guy who I've run into a couple of times who seems very social with everybody asked me for my number. I didn't want to be one of those girls who was like "I have a boyfriend!" if he was just trying to make friends on campus because we live in the same building and have the same major. Was that wrong of me to give it to him? I didn't have bad intentions I'm just trying to make friends and get to know people. And should I tell my boyfriend? Please don't be rude, I come from a small town where everybody already knows everyone so I haven't been in this situation except for when it's clear a guy is hitting on me. Thanks!