Fixed a bug in generating bit mask