@SuppressWarnings("unchecked")
	@Override
	public <T> T to(Class<T> klass) throws PDUException
	{
		Set<T> result = new HashSet<>();
		long bitmapValue = new UnsignedInteger(bitmap, bitmap.length).toLong();

		if (Long.class.isAssignableFrom(klass) || long.class.isAssignableFrom(klass))
		{
			return (T) (Long) bitmapValue;
		}
		else if (!Set.class.isAssignableFrom(klass))
		{
			throw new IllegalArgumentException(klass.getCanonicalName() + " is not assignable to Set");
		}

		Method factoryMethod = resolveValueToFlagBitmapFactoryMethod((Class<? extends Bitmappable>) elementType);

		try
		{
			if (bitmapValue == 0)
			{
				T noFlag = (T) factoryMethod.invoke(null, 0L);
				if (noFlag != null)
				{
					result.add(noFlag);
				}
			}
			else
			{
				long counter = 0x01L;
				long maxBit = 0x01L << (bitmap.length * 8);

				while (counter <= maxBit)
				{
					if ((bitmapValue & counter) > 0)
					{
						result.add((T) factoryMethod.invoke(null, counter));
					}

					counter <<= 1;
				}
			}
		}
		catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e)
		{
			throw new PDUException("Could not convert to " + klass.getCanonicalName(), e);
		}

		return (T) result;
	}