public static String addSpaceOnByteBoundary(String str, InputMode mode) {
		StringBuilder sb = new StringBuilder();

		// First remove all white spaces so we start from a clean string.
		str = str.replaceAll("\\s", "");

		int byteLength = 0;
		if (mode == InputMode.HEX) {
			byteLength = 2;
		}
		if (mode == InputMode.BINARY) {
			byteLength = 8;
		}

		// Now separate every 8th or 2nd char, depending on the format given.
		for (int i = 0; i < str.length(); i++) {
			sb.append(str.charAt(i));
			if ((i + 1) % byteLength == 0) {
				sb.append(" ");
			}
		}

		return sb.toString().trim();
	}
Formats a string by adding spaces on each byte boundary. The input mode specifies whether
this boundary is every 2(hex) or 8(binary) characters.

@param str
@param mode hex or binary
@return
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/instructionsearch/util/InstructionSearchUtils.java