19 votes

Program that converts a number to a letter of the alphabet - follow-up

int letter is not a letter. When printing you call it The number. Name it accordingly: ...
vnp's user avatar
  • 56.4k
13 votes

Program that converts a number to a letter of the alphabet - follow-up

Bug: When you feed an empty file to your program, it ends up in an endless loop. Bug: the 24th letter of the English alphabet is X, not S. Instead of const char * ...
Roland Illig's user avatar
  • 21.3k
12 votes

Converting between std::wstring and std::string

It really depends what codecs are being used with std::wstring and std::string. This answer assumes that the ...
Jamerson's user avatar
  • 303
10 votes

Converting the DateTime to and from Unix epoch times

Note that DateTimeOffset.ToUnixTimeSeconds and DateTimeOffset.FromUnixTimeSeconds exist as of .NET 4.6. Consider using those ...
Bob's user avatar
  • 459
10 votes

Convert a custom object to a query string

I wouldn't go the StringBuilder route, simply because you need to handle the "what if I'm at the start/end" problem. Instead, simply collect the "URL_translated" ...
BCdotWEB's user avatar
  • 11.2k
10 votes
Accepted

Represent integer as binary in C

More specific types are available for an eight bit number, such as uint8_t static keyword is dangerous (when used as an output ...
Ted Brownlow's user avatar
  • 1,632
10 votes
Accepted

Convert bool to int and int to bool

Don't overengineer things: it leads to code bloat. As you know, bool is already a subclass of int, so conversion between the two ...
FMc's user avatar
  • 12.7k
9 votes
Accepted

Find a value in a comma delimited String

This could be a better/cooler way: return (parameter as string)?.Split(',').Contains(value as string) ?? (object)false; Your example is so short that I don't ...
t3chb0t's user avatar
  • 44.3k
9 votes

Convert a custom object to a query string

In places where the type is obvious (or irrelevant) then feel free to use var instead of the type name. Also, consider not naming your variable after the type; this ...
Dan Oberlam's user avatar
  • 7,804
8 votes
Accepted

Bytes to binary conversion function

It's not terrible as it stands, but I think there are some ways it might be improved. Include all needed files The function needs several #include files that are ...
Edward's user avatar
  • 66.4k
7 votes
Accepted

Interpret YYYYMMDD as the nth day of the year

As you already use pandas, you are right that there is no overhead on using Timestamps (the kind of objects returned by ...
301_Moved_Permanently's user avatar
7 votes
Accepted

Convert mixed-format phone numbers to pure numbers

You can extract that logic to a simple dedicated method. Your solution is over-complicated for such a simple task so I will offer an alternative solution. Let's inspect the problem - You get some ...
Denis's user avatar
  • 8,458
7 votes

JavaScript string to Unicode (Hex)

This is regarding the edge-cases and test cases mentioned in the question: [...characters] // or Array.from(characters) handles splitting the characters of string ...
adiga's user avatar
  • 513
7 votes

Binary to decimal (and back) converter in c++

General Observations I'm mainly looking for error checking / type safety advice. There doesn't seem to be a lot of error checking on user input and user input is one of the places where error ...
pacmaninbw's user avatar
  • 23.8k
7 votes

Represent integer as binary in C

Bug Code attempts to form a string. Yet it lacks a terminating null character and space for it. // static char binary[10]; static char binary[11]; As a ...
chux - Reinstate Monica's user avatar
7 votes
Accepted

Number System Conversions with strtol

Style review(indentation, comments, readability, etc.) Noise const serves no purpose with const int base in the ...
chux - Reinstate Monica's user avatar
7 votes

Number System Conversions with strtol

chux and Toby already made many excellent points. I want to add one: Make the output useful by being less verbose Being verbose when printing an error message is helpful, but don't be verbose when ...
G. Sliepen's user avatar
  • 55.4k
7 votes
Accepted

library for converting numbers to HEX

The identifiers from <cstdint> are used without their namespace qualifiers. While your implementation is allowed to define global-namespace equivalents, that'...
Toby Speight's user avatar
  • 74.9k
6 votes

Convert Sql LIKE to Regex

Because the LIKE clause has a defined syntax, to do this right (meaning no clause will be incorrectly converted), you will need to use (or create) a simple lexer to ...
Damon Sutherland's user avatar
6 votes
Accepted

Converting the DateTime to and from Unix epoch times

You don't round inputs before the epoch start correctly. You should round towards minus infinity, not towards the epoch start. When you add x seconds to a ...
CodesInChaos's user avatar
  • 2,680
6 votes

C++ XOR Function

Well, obviously you should get rid of all that stringstream stuff in favor of the straightforward char buffer[100]; sprintf(buffer, "%016x", a ^ b); return buffer; ...
Quuxplusone's user avatar
  • 19.3k
6 votes

Converting XML to DOT

There's an XML syntax for DOT called DotML at http://martin-loetzsch.de/DOTML/. Generating a generic DotML tree from XML is very straightforward using XSLT. Most of it is just: ...
Michael Kay's user avatar
6 votes
Accepted

Convert an image to 8-bit color

The MSDN example is saving to a physical file, so the method incurs I/O - yours streams it to a MemoryStream, so it definitely feels more efficient. I'm a bit (pun ...
Mathieu Guindon's user avatar
6 votes

Enum with a lot of items and a long case statement to convert from string

Update Added constructor parameter for the dictionary to avoid lower/capital letter case problems as pointed in the comments. There are 2 solutions: First option would be to map ...
Denis's user avatar
  • 8,458
6 votes
Accepted

constexpr Endian conversion in c++14

In all, this looks pretty solid to me, so I have only a few suggestions: Eliminate spurious inline The inline keyword is only ...
Edward's user avatar
  • 66.4k
6 votes
Accepted

Normalizing mixed format nested dictionary with delimiter separated keys

Ok, so you have a arbitrary deep path and need to get a dictionary out of it. For this you can use an infinitely nestable defaultdict, as shown in this answer by @...
Graipher's user avatar
  • 40.9k
6 votes
Accepted

process numerical input arguments of mixed ints, floats, and "array-like" things of same length>1

I suggest using isinstance instead of type to check the types of variables. You can read about it in details here: What are the ...
Georgy's user avatar
  • 1,939

Only top scored, non community-wiki answers of a minimum length are eligible