public static String toHex(String binaryStr, boolean zeroFill) {

		StringBuilder sb = new StringBuilder();

		// Do some initial formatting of the binary string to separate the bytes for easier
		// reading.
		binaryStr = binaryStr.replaceAll("\\s", "");
		binaryStr = addSpaceOnByteBoundary(binaryStr, InputMode.BINARY);

		// Now split the binary string on byte boundaries.
		String[] instrBytes = binaryStr.split("\\s");

		// For each byte, convert it to hex.  If there are any masked characters they will
		// be identified by a '.', so we can't show this as hex; just keep as binary and 
		// put in brackets to more easily identify.
		for (String binary : instrBytes) {

			if (binary.contains(".")) {
				sb.append("[").append(binary).append("]").append(" ");
			}
			else {

				// If we're here, then take the full 8 bits and convert to 
				// hex, making sure that if a single character is the result, we
				// zero-fill to make more readable.
				int decimal = Integer.parseInt(binary, 2);
				String hex = Integer.toString(decimal, 16);

				if (zeroFill && hex.length() == 1) {
					hex = "0" + hex;
				}
				sb.append(hex).append(" ");
			}
		}
		return sb.toString();
	}
Converts the given binary instruction to hex.  

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