我正在尝试解码位掩码
[Flags]
public enum Amenities
{
BusinessCenter = 1,
FitnessCenter = 2,
HotTub = 4,
InternetAccess = 8,
KidsActivities = 16,
Kitchen = 32,
PetsAllowed = 64,
Pool = 128,
Restaurant = 256,
Spa = 512,
Whirlpool = 1024,
Breakfast = 2048,
Babysitting = 4096,
Jacuzzi = 8192,
Parking = 16384,
RoomService = 32768,
AccessibleTravel = 65536,
AccessibleBathroom = 131072,
RollShower = 262144,
HandicappedParking = 524288,
InRoomAccessibility = 1048576,
AccessibilityDeaf = 2097152,
BrailleSignage = 4194304,
FreeAirportShuttle = 8388608,
IndoorPool = 16777216,
OutdoorPool = 33554432,
ExtendedParking = 67108864,
FreeParking = 134217728
}
如何编写一个函数来解码像 5722635 这样的值并返回以 5722635 编码的所有便利设施的列表。
结果应如下所示:
该物业有以下设施:
- 商业中心
- 健身中心
- 互联网
- 现场可用的水疗中心
- 保姆
- 停車處
- 无障碍旅行路径
- 无障碍浴室
- 无障碍淋浴间
- 客房内无障碍设施
- 盲文或凸起标牌
我一直在尝试像
public List<Amenities> Decode(long mask)
{
var list = new List<Amenities>();
for (var index = 0; index < 16; index++)
{
var bit = 1 << index;
if (0 != (bit & mask))
{
list.Add(new Amenities(index));
}
}
return list;
}
但不能让它工作。任何有关如何使这项工作正常工作的建议将不胜感激。