• GluWu@lemm.ee
    link
    fedilink
    arrow-up
    16
    ·
    11 months ago

    Ascii hex is hot but if you can flirt in binary that’s pretty attractive too.

    49 20 6E 65 65 64 20 74 6F 20 63 75 6D

      • AVincentInSpace@pawb.social
        link
        fedilink
        English
        arrow-up
        23
        ·
        edit-2
        11 months ago

        Not to worry I will teach you!

        Hexadecimal is a method of representing numbers much like the decimal you’re probably used to, only it’s base 16 instead of base 10. It’s used a lot in computer science since one digit of hexadecimal exactly corresponds to four digits of binary and that makes it really easy to write long sequences of binary without wearing out your hand.

        In order to explain base 16, I need to tell you how base 10 works first so you have a point of comparison. This’ll be a bunch of stuff you already know but bear with me. With base 10, you add a new digit every time you count past 9, and each digit in a number is worth 10 times the one to the right of it. Starting at the right you have the ones place, then the tens place, then the hundreds place (10 times 10), then the thousands place (10 times 10 times 10), and so on. The number 349, for example, can be written as 3 hundreds, 4 tens, and 9 ones (3*100 + 4*10 + 5). The thing is, there’s nothing magical about the number 10. You can pick any number you like and have each digit worth that many times the previous, and add a new digit each time you count past one less than that number. In base 16, you add a new digit each time you count past 15, and you have the ones place, to the right of that is the sixteens place, then the 256s place (16 times 16), then the 4096s place (16 times 16 times 16), and so on. The number three hundred and forty nine from earlier can be written as one 256, five sixteens, and 13 ones (1*256 + 5*16 + 13). But wait – 13 ones? How do we write that in a single digit? This is where computer scientists had to get inventive. For the digits 0 through 9, we just use the regular digits, but for 10 through 15 we use A through F. So the number 349 (base 10) is written as 15D in hexadecimal (again, that’s one 256, five 16s, and D ones (A=10, B=11, C=12, D=13)). It’s also common practice to write 0x before a hexadecimal number so it’s clear it’s not a decimal one in case the number doesn’t happen to have any letters in it, so it would more properly be 0x15D.

        Got all that? Good, let’s press on.

        Now we need to talk about representing letters using hexadecimal. Long story short, the only thing computers know how to deal with is numbers. Any other kind of data you want them to interact with (text, images, audio, etc.) has to be converted into a sequence of numbers first. The most obvious way to do this for text is to just say 1=A, 2=B etc. but then you kind of run into a wall when you want to add lowercase letters, numbers, punctuation etc. Some very smart computer scientists in the 1960s came up with a standard way of mapping basically every key on your keyboard to a number between 0 and 127. (That may seem oddly specific, but it’s a perfectly round number in binary.) They called it the American Standard Code for Information Interchange, or ASCII, and it’s still in use today (albeit in an expanded form called Unicode that allows non-English letters, emoji etc., that maps each character to a number between 0 and 2147483647).

        It just so happens that a number between 0 and 255, such as a single letter in ASCII, can be represented using two hex digits. For this reason, any hex string that encodes ASCII will be divided into pairs of digits. The OP might have been kind enough to put spaces between the pairs like you see here, they might not. If they don’t, you’ll have to do it in your head; i.e. 4A5C204E becomes 4A 5C 20 4E. (If there are an odd number of digits total, it’s not valid ASCII.) A good way to make sure you’re counting right is that with the exception of 20 (ASCII space) the first digit of every pair will be either 4, 5, 6, or 7.

        While ASCII can encode any letter, number, or punctuation on your keyboard, most hex you encounter on the internet will only be letters and spaces. For this there are three things you need to know:

        Space = 0x20
        Capital A = 0x41
        Lowercase A = 0x61

        Every letter after that, you’ll just count in hexadecimal till you reach it; e.g. 42 = capital B, 43 = capital C, …, 49 = I, 4A = J, …, 4F = O, 50 = P, …, 5A = Z. Same thing for the lowercase letters only start at 0x61. Space is always 0x20. The letters that start with 4 or 6 and the second digit is between 0 and 9 are easy since it’s just that letter of the alphabet, i.e. the fifth letter of the alphabet is E so 45 = E and 65 = e.

        Got all that? Congrats! Now you can read hex without using a converter!

        Here’s OP’s original message:
        49 20 6E 65 65 64 20 74 6F 20 63 75 6D

        49 = capital I
        20 = space
        6E = lowercase N
        65 = lowercase E
        etc. etc.
        The first three words are “I need to”. I’ll leave decoding the last three pairs up to you.

        (Sorry if this explanation was a bit rambly – it’s late in the day and I’m on mobile)