Binary and/or hexadecimal, %!@#, do you speak it? π€
As we get AI to write more of our code, we may need to learn how to read its more unique way of representing solutions that aren't exactly human-friendly.
Hi everybody - Iβve been using AI to more increasingly write code for things that I would have normally written manually. For example, I recently had it generate some JavaScript as part of a simple permissions system for a user sign-in:
const PERMISSIONS = {
READ: 1 << 0, // 0001 => 1
WRITE: 1 << 1, // 0010 => 2
EXECUTE: 1 << 2, // 0100 => 4
DELETE: 1 << 3 // 1000 => 8
};
function hasPermission(userPermissions, permission) {
return (userPermissions & permission) !== 0;
}
function addPermission(userPermissions, permission) {
return userPermissions | permission;
}
function removePermission(userPermissions, permission) {
return userPermissions & ~permission;
}
Here is where things got interesting. The approach the AI assistant suggested involved using binary values and using bitmasks instead of boolean flags. This is certainly not my default approach for solving this, and my attempts at nudging it to not use binary values didnβt work too well. It insisted on using this approach.
I felt a bit like Frank Whaley being lectured at by Samuel L. Jackson in the classic Pulp Fiction scene whereβ¦similar stuff happens:
The bigger point is this. As we rely on AI assistants to write more and more of our code, they will generate solutions that are optimized for it as opposed it being optimized for us humans. To describe differently, if we put the AI in the driverβs seat, it may take routes to get to the destination that might be different from ones weβd take:
The solution sometimes isnβt to fight the AI assistant. The solution is to better understand what the AI assistant is doing so that we can continue collaborating effectively with it. This specific binary/not-binary situation was the inspiration for my latest content drop where I explain how to work with both binary and hexadecimal decimal values:
You can view the video by clicking the YouTube thumbnail above, but if you prefer to read this content instead, you can go to my Counting in Binary and Hexadecimal article.
Till Next Time
Cooperating with AI assistants was not on my bingo card, but here we are. While I havenβt gotten to saying Please and Thank You as part of my interactions, the following comic will certainly make me think otherwise:
What are your thoughts? Feel free to chime in on the forums, on Twitter / X, or in the comments below with your thoughts.
Cheers,
Kirupa πΎ