Skip to main content
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
  • 58.7k
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.9k
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.4k
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,692
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
  • 13.1k
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
  • 8,049
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
  • 67.2k
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
  • 26.1k
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's user avatar
  • 36.4k
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 ...
Sᴀᴍ Onᴇᴌᴀ'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's user avatar
  • 36.4k
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
  • 69.3k
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
  • 88.3k
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

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
  • 41.7k
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,997
6 votes

fasm convert hex byte to binary string

In a high-level language, I would write it as: ...
Roland Illig's user avatar
  • 21.9k
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-...
Matthieu M.'s user avatar
  • 6,389
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 ...
Roland Illig's user avatar
  • 21.9k
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....
aepot's user avatar
  • 2,119
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, "...
Toby Speight's user avatar
  • 88.3k
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. ...
Blindman67's user avatar
  • 22.9k
6 votes

Number System Conversions with strtol

Everything that chux said, and: The memory allocation is unused and leaked. Look at this: ...
Toby Speight's user avatar
  • 88.3k
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 ...
Toby Speight's user avatar
  • 88.3k
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: ...
dfhwze's user avatar
  • 14.2k
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's user avatar
  • 13.8k

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