29 votes
Accepted

Convert Persian and Arabic digits to English

Be nice to the maintenance programmer, even (especially?) if you expect it to be you. If you're mixing characters which are visually indistinguishable but don't need to be literal self-representations,...
Peter Taylor's user avatar
  • 24.1k
15 votes
Accepted

Binary to decimal converter

What would Bob do? You've written an interactive program, but the user does not know what your program does. Therefore, Bob—the generic user—might accidentally write "test" instead of a ...
Zeta's user avatar
  • 19.3k
14 votes
Accepted

C++ basic bank money class

Store Money as Fixed-Point Monetary quantities are the classic example of something that might have fractional values, but you do not want to represent as a floating-point number, because you need ...
Davislor's user avatar
  • 7,371
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
9 votes
Accepted

The base-ten value of n-base number with Python

A few quick comments: Use a proper function here, not a lambda. It’s generally more readable, and should be preferred unless you’re writing a ~very short function. And then use different variable ...
alexwlchan's user avatar
  • 8,545
9 votes

Karazuba Algorithm with arbitrary bases

Combine division and modulus Use https://docs.python.org/3/library/functions.html#divmod rather than this: digits.append(int(n % b)) n //= b Replace ...
Reinderien's user avatar
  • 61.9k
8 votes
Accepted

Implementing my own Integer.toBinaryString(int n) method

The exercise calls for bit shifting. Only bit shifting, nothing else, really. Your main tools are: checking if the last bit is 0 or 1 with: num & 1 then shift ...
janos's user avatar
  • 111k
8 votes
Accepted

Integer to binary using an old-school way

Functional extraction Your method does not do toBinary, it does: read input from user convert to binary print back for user When you have methods that do ...
rolfl's user avatar
  • 97.3k
8 votes
Accepted

Base 26 (letters) and Base 10 using recursion

As others already said, recursion doesn't quite fit here. But I’d say it doesn't fit because strings are immutable. In your implementation, you are either concatenating strings or slicing them, which ...
301_Moved_Permanently's user avatar
8 votes
Accepted

Hex dump of a list of 16-bit numbers

Here are some comments on your code: I assume the structure of the input data is to be taken as it is: one long list where only the 1 out of 8 values contribute to the output. ...
trincot's user avatar
  • 557
8 votes
Accepted

Convert decimal to binary

Terminology It's important to be able to understand (and describe) what's actually going on. Your program converts from an integer decimal string representation to an integer using ...
Reinderien's user avatar
  • 61.9k
8 votes
Accepted

Printing a number in binary in C

The obvious portability problem is that we have b[i^SIZE-1] where I'd expect b[SIZE-1-i]. That looks like an error of judgement:...
Toby Speight's user avatar
  • 74.9k
7 votes

Roman Numeral class in Python

I do not really know how you plan to use your RomanNumeral object. From what's in the constructor, I guess you'd use it to convert a string corresponding to a ...
SylvainD's user avatar
  • 29.2k
7 votes

Convert binary string to decimal number

Well, first of all the description is wrong. strbin_to_dec() should be strbin_to_i(), because it parses a base-2-number, instead ...
Deduplicator's user avatar
  • 19.1k
7 votes
Accepted

String to binary converter

I would change ...
KYHSGeekCode's user avatar
7 votes

Decimal to Binary in Rust

isn't it better to write input as a macro ? No. At best it might work as a generic function. how can i write to_binary as pure function ? It already is a pure function, it doesn't mutate or ...
Winston Ewert's user avatar
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
6 votes

Convert Persian and Arabic digits to English

You can use capture groups return string.replace(/([٠١٢٣٤٥٦٧٨٩])|([۰۱۲۳۴۵۶۷۸۹])/g, function(m, $1, $2) { return m.charCodeAt(0) - ($1 ? 1632 : 1776); }); <...
Tushar's user avatar
  • 2,992
6 votes
Accepted

Convert boolean list to list of base10 integers

The individual steps that you describe in the Problem section are each simple and easy to follow. Yet you write your code in basically a single line. To understand it I had to tear it apart like you ...
Roland Illig's user avatar
  • 21.3k
6 votes
Accepted

Python binary calculator

General design comment The fact that a binary number needs to access the application using it looks like a huge design issue. A quick fix for this is to provide the desired numbers of bits instead - ...
SylvainD's user avatar
  • 29.2k
6 votes

Converting long values in Java to unsigned strings

Since you're asking about readability, let's take a look at that. Your functions and variables could be named better. Especially parts like this: ...
Mast's user avatar
  • 13.4k
6 votes
Accepted

Hex string to Base64 in Haskell

Ok, for starters, it mentions on the first challenge: Always operate on raw bytes, never on encoded strings. Only use hex and base64 for pretty-printing. Since ...
hololeap's user avatar
  • 176
6 votes
Accepted

Convert Integer to Binary String

Your implementation seems fine at a glance, but Python actually provides two really easy ways to do this: string.format bin ...
Dan Oberlam's user avatar
  • 7,804
6 votes

C++ basic bank money class

Store money as a single integer Using integers instead of floating point values to store an amount of money is a very good idea. However, you don't need two integers, you can just use one, that stores ...
G. Sliepen's user avatar
  • 55.4k
6 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 - e.g. see answers ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
5 votes
Accepted

Base-changing numbers in Java

Bugs You've got a few bugs; System.out.println(BaseConverter.changeBase(""+0x7FFF_FFFF_FFFF_FFFFL, 10, 16, true)); Will give ...
Pimgd's user avatar
  • 22.3k
5 votes

JavaScript function to convert decimal number to binary

Strictly speaking, the number parameter isn't decimal; it's just an abstract number. (This is more a criticism of the terminology in your question title than of ...
200_success's user avatar
5 votes
Accepted

Multiplying and Adding Large Numbers

It's really worth making your big number be a class. This will give you the ability to change the internal representation without altering client code write operators (...
Toby Speight's user avatar
  • 74.9k
5 votes
Accepted

C binary number converter (Hex and Decimals)

First things first, props to you for learning good old C in the day of dynamically typed high level languages! Now on to the review... Error checking Right now, there's nothing to stop me from ...
Phil Kiener's user avatar
5 votes

Roman numerals to Arabic

You've gotten a really nice answer regarding the logic, variable names, etc. -- all of the actual code. I want to comment on the structure of your program: ...
Cris Luengo's user avatar
  • 5,573

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