News for hackers. Stuff that matters.
Re:Ask HN: What are the “lost arts” of our field? by mattbgates on Monday August 14, 2023 @03:11PM (#37125429)
Back in my day... probably not technically a lost art, but an interesting lesson in math.

I remember I was in computer science class. I was 17 years old.

And the teacher taught us how to read binary and how to calculate it. He said binary was math which is a universal language that even aliens could understand and would allow us to communicate though we'd still run into the struggle of converting that binary to actual meanings, such as converting binary to English or vice versa.

We often don't think about it, but our programming technology is based on binary calculations.

I'd put the Conversion to Binary or from Binary in the lost arts category because I highly doubt it is ever taught, not even in computer science classes nowadays because its just slow and boring to do the conversions.

But if you do think about it, he wasn't wrong.

For those who are curious about it:

Converting binary to English or math involves interpreting the binary representation of numbers or characters into their corresponding decimal values or ASCII representations. Here's how you can do it:

Binary to Decimal (Math): Each digit in a binary number represents a power of 2. To convert binary to decimal, start from the rightmost digit and multiply each digit by 2 raised to its position, then sum up the results.

Example: Convert binary 1101 to decimal.

1 * 2^3 + 1 * 2^2 + 0 * 2^1 + 1 * 2^0 = 8 + 4 + 0 + 1 = 13

Binary to ASCII (English): ASCII (American Standard Code for Information Interchange) is a character encoding standard where each character is represented by a unique numeric value. In ASCII, each character is assigned a decimal value, which can be converted from binary.

Example: Convert binary 01001000 01100101 01101100 01101100 01101111 to ASCII (which represents the word "Hello").

01001000 -> 72 (H)

01100101 -> 101 (e)

01101100 -> 108 (l)

01101100 -> 108 (l)

01101111 -> 111 (o)

So, to convert binary to English or math, follow these steps:

For English (ASCII characters):

Divide the binary into groups of 8 bits (1 byte).

Convert each group of 8 bits to decimal.

Find the ASCII character associated with the decimal value.

For Math (Decimal):

Write down the binary number.

Multiply each binary digit by 2 raised to its position (starting from the rightmost position).

Sum up the results to get the decimal equivalent.

Keep in mind that this process is straightforward for numbers and ASCII characters, but other types of binary data (like images or files) may require different methods to interpret.

I believe there was a message in a crop field at one time:

Re:Ask HN: What are the “lost arts” of our field? by xp84 on Monday August 14, 2023 @03:43PM (#37125849)
Tangentially related: storing a bitmask in your database (as a single 32-bit value) to track many flags, and using bitwise math to manipulate/interpret it. Much more space efficient than what everyone would do now (a bunch of tinyints, enums, or booleans) but obviously you’d be rightly fired out of a cannon now for introducing something so difficult to grasp for young devs, just to save “cheap” memory and storage.
Re:Ask HN: What are the “lost arts” of our field? by dekhn on Monday August 14, 2023 @08:09PM (#37128470)
I have a few simple bit questions in my coding interviews and most programmers simply don't know how to set a bit in a byte (or word), rotate bits in a byte (or word), or what endian is.
Re:Ask HN: What are the “lost arts” of our field? by warrenm on Wednesday August 16, 2023 @03:40PM (#37152540)
Bit masks are cool

They are also very fragile

Far better to have some maintainable and extendable (what happens when you exceed 32 binary flags?) than being overly clever for the sake of saving a couple bytes of storage

Re:Ask HN: What are the “lost arts” of our field? by xp84 on Friday August 18, 2023 @09:56AM (#37175667)
No dispute there, it would be silly now, I just think it was kind of cool how programmers used to understand how binary worked, and appreciate that it was worth it at one point to use 1 actual bit to store a true/false value.
Re:Ask HN: What are the “lost arts” of our field? by frfl on Monday August 14, 2023 @03:44PM (#37125856)
In the 2010s binary was taught in high school intro to CS and in university CS classes. I don't know about bootcamps though, I doubt it is taught there.

What isn't really taught is binary representations and what things look like in memory. I think there was one class in university that covered it, but just briefly.

Re:Ask HN: What are the “lost arts” of our field? by rthomas6 on Monday August 14, 2023 @04:16PM (#37126238)
Binary is used often by embedded programming/FPGA dev types. I use binary and hexadecimal every day.