Tag Info

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,...
• 24.1k
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 ...
• 19.3k
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 ...
• 7,371
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 ...
• 1,632
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 ...
• 8,545

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 ...
• 61.9k
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 ...
• 111k
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 ...
• 97.3k
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 ...
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. ...
• 557
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 ...
• 61.9k
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:...
• 74.9k

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 ...
• 29.2k

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 ...
• 19.1k
Accepted

String to binary converter

I would change ...
• 298

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 ...
• 30.2k

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 ...

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); }); <...
• 2,992
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 ...
• 21.3k
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 - ...
• 29.2k

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: ...
• 13.4k
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 ...
• 176
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 ...
• 7,804

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 ...
• 55.4k
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 ...
• 27.6k
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 ...
• 22.3k

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 ...
• 144k
Accepted

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 (...
• 74.9k
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 ...
• 685