public void setCodes(byte[] codes) {
		byte[] possible = supportedCodes();

		List<Byte> newCodesList = new ArrayList<>(maxCodeCount());
		int newCount = 0;
		for (int i = 0; i < codes.length; i++) {
			byte c = codes[i];
			if (Arrays.binarySearch(possible, c) < 0) {
				throw new IllegalArgumentException("Code " + codeToString(c)
						+ " is not valid for this chip.");
			} else if (newCodesList.size() == maxCodeCount()) {
				throw new IllegalArgumentException("This chip can only have "
						+ maxCodeCount() + " different chip codes at most.");
			} else if (!newCodesList.contains(c)) {
				newCodesList.add(c);
				newCount++;
			}
		}

		Collections.sort(newCodesList);
		for (int i = 0; i < maxCodeCount(); i++) {
			if (i < newCount) {
				this.codes[i] = newCodesList.get(i);
			} else {
				this.codes[i] = -1;
			}
		}
	}