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: ...
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 * ...
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" ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
7
votes
Accepted
Convert integer to Roman numeral string
For a beginner it seems fine. There are some improvements that can be made. The points below are analysis of the given code.
Obviously there are examples of simpler implementations to convert numbers ...
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 ...
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 ...
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'...
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 ...
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 @...
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 ...
6
votes
6
votes
Conversion into hexadecimal using C++
Disclaimer: if you want to use std::ostream and its manipulators, see @tinstaafl's answer.
Principle of least capabilities
Your functions arguments are over-...
6
votes
Implementation of itoa
The code almost works.
To make it work in all cases, test the program with Valgrind, which detects undefined behavior because of invalid memory access. This will prove that the buffer needs to be 11 ...
6
votes
ConvertAll Methods Implementation for Multidimensional Array in C#
Your code is repetitive. To solve that I'll show some array-related easy cheats.
As @Olivier said, Array implements IEnumerable....
6
votes
Bytes to binary conversion function
Interface
I find it helps if we use verbs for function names. Instead of saying, "Here's some memory, let's binary() it," it's more natural to say, "...
6
votes
Accepted
Convert number 1-5 from its spelt-out form
Complexity and performance
There are many ways to write this type of function and the best is determined by the number of input states. In your example you have 6 different input states 1-5 and NaN.
...
6
votes
Number System Conversions with strtol
Everything that chux said, and:
The memory allocation is unused and leaked. Look at this:
...
6
votes
Arbitrary-layout Floating-point Number conversion library
Naming
The established convention in C and C++ is that we use all-caps names for preprocessor macros and not for other identifiers (except for initial-caps type name placeholders in templates, which ...
5
votes
Converting a boolean list to string, and vice versa
I challenge the need for a list of booleans. There are alternatives available in the .NET Framework that deal with a sequence of booleans.
If the flags are static and fixed:
...
5
votes
Internal and external datatype converter
There are a couple of things that come to mind when reading your code. I'll write them down, in no particular order of importance.
Your example imports your library like this:
...
Mast♦
- 13.8k
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
converting × 377c# × 68
c++ × 66
python × 62
strings × 54
java × 51
beginner × 46
performance × 43
c × 34
datetime × 29
javascript × 27
python-3.x × 25
reinventing-the-wheel × 21
integer × 18
ruby × 16
numbers-to-words × 16
algorithm × 13
parsing × 13
roman-numerals × 13
programming-challenge × 11
.net × 10
php × 9
array × 9
json × 9
object-oriented × 8