<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Code on Bald Engineer</title><link>https://www.baldengineer.com/category/code</link><description>Recent content in Code on Bald Engineer</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Fri, 26 Jul 2024 14:57:29 +0000</lastBuildDate><atom:link href="https://www.baldengineer.com/category/code/index.xml" rel="self" type="application/rss+xml"/><item><title>Python to set 8th bit in ASCII String</title><link>https://www.baldengineer.com/python-to-set-8th-bit-in-ascii-string.html</link><pubDate>Sun, 30 Jun 2024 17:18:31 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=9024</guid><description>The Apple II’s ROM has the 8th bit set for all of its ASCII strings. This convention makes it difficult to search the ROM for hex strings quickly. This Python script takes an ASCII string and returns the HEX string with (and without) the 8th bit set.&#10;Python Code input_string = "Mega IIe" def string_to_hex_ascii(input_string, set_bit_8=False): hex_values = [] for char in input_string: # Get the ASCII value of the character ord() and convert it string # representing the hex() value # # [2:] strips the '0x' if (set_bit_8): hex_value = (hex(ord(char) | 0x80)).upper() # for Apple II, awww else: hex_value = (hex(ord(char))).upper() hex_values.append(hex_value[2:]) return hex_values def print_list_with_spaces(input_list): # Join the list elements into a single string with spaces in between result = ' '.join(map(str, input_list)) print(result) def print_og_string_formatted(input_string): result = ' '.join(input_string) print(result) # Remind user of string print("Og : ", end='') print_og_string_formatted(input_string) # As-is ASCII in Hex hex_values_raw = string_to_hex_ascii(input_string) print("Raw : ", end='') print_list_with_spaces(hex_values_raw) # Hex with 8th bit set hex_values_8bit = string_to_hex_ascii(input_string, True) print("8bit: ", end='') print_list_with_spaces(hex_values_8bit) Disclaimer: I used ChatGPT to generate an initial script for converting an ASCII string to a list of hex values. Then, I wrote the rest.</description></item></channel></rss>