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 »

Review Suggested Edit

You can't approve or reject suggested edits because you haven't yet earned the Edit Posts ability.

Rejected.
This suggested edit was rejected about 1 year ago by H_H‭:

Byte is a unit, units are never plural (yes, some english dictionary say so but this is very stupid. Since you can have values that aren't integers)

65 / 255
  • ## C, 59 byte
  • ```c
  • h(n){return n&4?n&2?5:n&1?1e3:n&8?50:500:n&2?100:n&1?1:10;}
  • ```
  • ### Old version, 60 byte:
  • ```c
  • h(n){return n&4?n&2?5:n&1?1000:n&8?50:500:n&2?100:n&1?1:10;}
  • ```
  • Not very creative, there is probably a smaller version. Takes a ASCII character as argument and returns the value.
  • `n&4` separates `'V'`/`5`, `'L'`/`50`, `'D'`/`500` and `'M'`/`1000`, which have bit 2 set and end up in this part: `n&2?5:n&1?1000:n&8?50:500`, and `'I'`/`1`, `'X'`/`10`, `'C'`/`100` , which have bit 2 cleared and end up in this part: `n&2?100:n&1?1:10`.
  • A similar thing is done after that, of `'V', 'L', 'D', 'M'`, only `'V'` has bit 1 set, so if `n&2` is true, the value is 5. If not, we check bit 0 with `n&1` for `'M'` or 1000, bit 3 for `'L'` or `50` and if it is none of them it must be `'D'` or `500`. A similar thing is done for the numbers `100`, `1` and `10`. This has the nice side effect that it works work lower and upper case letters, since it ignores all bits >3.
  • Tried a version for EBCDIC-Encoding but that is longer (because some characters only differ at bit 4, which requires a `n&16`, which is 1 byte longer).
  • ## C, 59 bytes
  • ```c
  • h(n){return n&4?n&2?5:n&1?1e3:n&8?50:500:n&2?100:n&1?1:10;}
  • ```
  • ### Old version, 60 bytes:
  • ```c
  • h(n){return n&4?n&2?5:n&1?1000:n&8?50:500:n&2?100:n&1?1:10;}
  • ```
  • Not very creative, there is probably a smaller version. Takes a ASCII character as argument and returns the value.
  • `n&4` separates `'V'`/`5`, `'L'`/`50`, `'D'`/`500` and `'M'`/`1000`, which have bit 2 set and end up in this part: `n&2?5:n&1?1000:n&8?50:500`, and `'I'`/`1`, `'X'`/`10`, `'C'`/`100` , which have bit 2 cleared and end up in this part: `n&2?100:n&1?1:10`.
  • A similar thing is done after that, of `'V', 'L', 'D', 'M'`, only `'V'` has bit 1 set, so if `n&2` is true, the value is 5. If not, we check bit 0 with `n&1` for `'M'` or 1000, bit 3 for `'L'` or `50` and if it is none of them it must be `'D'` or `500`. A similar thing is done for the numbers `100`, `1` and `10`. This has the nice side effect that it works work lower and upper case letters, since it ignores all bits >3.
  • Tried a version for EBCDIC-Encoding but that is longer (because some characters only differ at bit 4, which requires a `n&16`, which is 1 byte longer).

Suggested about 1 year ago by MrDevel0per‭