Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

60%
+1 −0
Challenges Find the IP address class

C (gcc), 55 bytes a;f(char*s){for(;atoi(s)&128>>a&&a<4;a++);return 65+a;} Try it online! Just call atoi and start masking with 0x80. If true, keep looping and next che...

posted 16d ago by Lundin‭  ·  edited 12d ago by Lundin‭

Answer
#3: Post edited by user avatar Lundin‭ · 2024-12-10T08:42:30Z (12 days ago)
Loop condition would fail to stop in some valid test cases
  • # [C (gcc)], 50 bytes
  • <!-- language-all: lang-c -->
  • a;f(char*s){for(;atoi(s)&128>>a;a++);return 65+a;}
  • [Try it online!][TIO-m4ctnh7n]
  • [C (gcc)]: https://gcc.gnu.org/
  • [TIO-m4ctnh7n]: https://tio.run/##hc7RCoIwFAbg@z3FUIizLJnDylj5Loe55aBmzHklPvvKrooiORz44XzwH7W9KBUjSgOqRb/u2Wg6DxJDZ6Fnq0JUdY0Ss4xJr8PgHd3vMpRTTBttrNPUPBkFPPPNnBghqXXqOjSanvrQ2C5va0KsC/SG1gEjI6H0PoS5DQwkPH9Nwpj8PBSc52/7A4jDEqgWwFH8B0KUC6D8fnKKDw "C (gcc) – Try It Online"
  • ---
  • Just call atoi and start masking with 0x80. If true, keep looping and next check with 0x40 and so on, until the mask either results in zero or is right-shifted down to 0x00, meaning all bits in the ms nibble were set.
  • # [C (gcc)], 55 bytes
  • <!-- language-all: lang-c -->
  • a;f(char*s){for(;atoi(s)&128>>a&&a<4;a++);return 65+a;}
  • [Try it online!][TIO-m4i7px0j]
  • [C (gcc)]: https://gcc.gnu.org/
  • [TIO-m4i7px0j]: https://tio.run/##hc3fCoMgFAbwe59CCkLXFia5P9h6l4PpEjYbZlfRs7u1qw1i8XHgg/ODTx1uSsUI0hDVgd8NdDK9JxJCb8lAs5KfmwayDOpKQp5T6XUYvcNHkYOcY9pqY53G5m0xgSvbL40ilFqn7mOrcT2E1vZF1yBkXcAPsI5QNCGMn2NYJokhCSs@SSiVv4@SseLrVgA/bQAhNsCF/wecVxtgZWKOLw "C (gcc) – Try It Online"
  • ---
  • Just call atoi and start masking with 0x80. If true, keep looping and next check with 0x40 and so on, until the mask either results in zero or 4 bits have been checked, meaning all bits in the ms nibble were set.
#2: Post edited by user avatar Lundin‭ · 2024-12-06T14:15:58Z (16 days ago)
  • # [C (gcc)], 50 bytes
  • <!-- language-all: lang-c -->
  • a;f(char*s){for(;atoi(s)&128>>a;a++);return 65+a;}
  • [Try it online!][TIO-m4ctnh7n]
  • [C (gcc)]: https://gcc.gnu.org/
  • [TIO-m4ctnh7n]: https://tio.run/##hc7RCoIwFAbg@z3FUIizLJnDylj5Loe55aBmzHklPvvKrooiORz44XzwH7W9KBUjSgOqRb/u2Wg6DxJDZ6Fnq0JUdY0Ss4xJr8PgHd3vMpRTTBttrNPUPBkFPPPNnBghqXXqOjSanvrQ2C5va0KsC/SG1gEjI6H0PoS5DQwkPH9Nwpj8PBSc52/7A4jDEqgWwFH8B0KUC6D8fnKKDw "C (gcc) – Try It Online"
  • ---
  • Just call atoi and start masking with 0x80. If true, keep looping and next check with 0x40 and so on, until the mask is right-shifted down to 0x00 meaning all bits in the ms nibble were set.
  • # [C (gcc)], 50 bytes
  • <!-- language-all: lang-c -->
  • a;f(char*s){for(;atoi(s)&128>>a;a++);return 65+a;}
  • [Try it online!][TIO-m4ctnh7n]
  • [C (gcc)]: https://gcc.gnu.org/
  • [TIO-m4ctnh7n]: https://tio.run/##hc7RCoIwFAbg@z3FUIizLJnDylj5Loe55aBmzHklPvvKrooiORz44XzwH7W9KBUjSgOqRb/u2Wg6DxJDZ6Fnq0JUdY0Ss4xJr8PgHd3vMpRTTBttrNPUPBkFPPPNnBghqXXqOjSanvrQ2C5va0KsC/SG1gEjI6H0PoS5DQwkPH9Nwpj8PBSc52/7A4jDEqgWwFH8B0KUC6D8fnKKDw "C (gcc) – Try It Online"
  • ---
  • Just call atoi and start masking with 0x80. If true, keep looping and next check with 0x40 and so on, until the mask either results in zero or is right-shifted down to 0x00, meaning all bits in the ms nibble were set.
#1: Initial revision by user avatar Lundin‭ · 2024-12-06T14:12:30Z (16 days ago)
# [C (gcc)], 50 bytes

<!-- language-all: lang-c -->

    a;f(char*s){for(;atoi(s)&128>>a;a++);return 65+a;}

[Try it online!][TIO-m4ctnh7n]

[C (gcc)]: https://gcc.gnu.org/
[TIO-m4ctnh7n]: https://tio.run/##hc7RCoIwFAbg@z3FUIizLJnDylj5Loe55aBmzHklPvvKrooiORz44XzwH7W9KBUjSgOqRb/u2Wg6DxJDZ6Fnq0JUdY0Ss4xJr8PgHd3vMpRTTBttrNPUPBkFPPPNnBghqXXqOjSanvrQ2C5va0KsC/SG1gEjI6H0PoS5DQwkPH9Nwpj8PBSc52/7A4jDEqgWwFH8B0KUC6D8fnKKDw "C (gcc) – Try It Online"

---

Just call atoi and start masking with 0x80. If true, keep looping and next check with 0x40 and so on, until the mask is right-shifted down to 0x00 meaning all bits in the ms nibble were set.