this post was submitted on 30 Jun 2024
571 points (98.1% liked)
Programmer Humor
19557 readers
737 users here now
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I’m not sure if you’re getting it, so I’ll explain just in case.
In computer science a few conventions have emerged on how numbers should be interpreted, depending on how they start:
0b
, so0b1001110
0
, so0116
0x
, so0x8E
If your zip code starts with 9, it won’t be interpreted as octal. You’re fine.
Well, you're right. I wasn't getting it, but I've also never seen any piece of software that would treat a single leading zero as octal. That's just a recipe for disaster, and it should use
0o116
to be unambiguous(I am a software engineer, but was assuming you meant it was hardcoded to parse as octal, not some weird auto-detect)
I thought JavaScript did that, but it turns out it doesn’t. I thought Java did that, but it turns out it doesn’t. Python did it until version 2.7: https://docs.python.org/2.7/library/functions.html#int. C still does it: https://en.cppreference.com/w/c/string/byte/strtol
Interesting that
strtol
in C does that. I've always explicitly passed in base 10 or 16, but I didn't know it would auto-detect if you passed 0. TIL.