Questions tagged [converting]

Converting involves changing data from one data type or format to another.

Filter by
Sorted by
Tagged with
26
votes
6answers
104k views

Conversion between enum and string in C++ class header

I have the following redundant-feeling design to convert between enums and strings regarding a class that stores enums. The ...
10
votes
2answers
2k views

Number to Words

I have to convert positive numbers, that are less than 1000, to words. A quick search didn't find anything that looked good to my eye, so I came up with the following. While I was at it I expanded ...
10
votes
1answer
811 views

Spell a given number in English

I wrote a program that will take a number from 0 to 999,999,999,999 and spell out that number in English. How could I improve the readability of my code? ...
8
votes
3answers
7k views

Converting a number to the text representation

Following along with some previous questions: The @dbasnett original here: Number to Words @nhgrif's here: Int extension for translating integer to plain English I wanted to answer the original ...
12
votes
4answers
3k views

Type system for different representations of angle value

I want to implement a Type system for different representations of an angle value. Motivation to implement this as a type system comes from this question. Angle can be represented using the ...
9
votes
2answers
239 views

ConvertAll Methods Implementation for Multidimensional Array in C#

I am trying to perform some conversions with multidimensional array in C# and I have checked the discussion ConvertAll and 2-dimensional arrays. I found that ...
9
votes
3answers
22k views

Number-to-word converter

My code works, but the aesthetic of the code seems to need some real work. The logic is simple enough: Create three lists of words that will be used throughout the conversion Create three functions: ...
7
votes
5answers
11k views

Creating a numeric phone keypad

I'm writing a Telephone class and it has a method called getDigits which takes in a String parameter and returns the number that would appear on your phone if you ...
40
votes
9answers
110k views

Converting between std::wstring and std::string

While researching ways to convert back and forth between std::wstring and std::string, I found this conversation on the MSDN ...
10
votes
3answers
28k views

Function that convert decimal to binary

I have a function that converts an integer to its binary representation. I am wondering if there is any way I can improve the function. ...
33
votes
2answers
112k views

Integer to Alphabet string ("A", "B", ...."Z", "AA", "AB"...)

So this question is prompted by two things. I found some code in our source control doing this sort of things. These SO questions: https://stackoverflow.com/questions/297213/translate-an-index-into-...
4
votes
2answers
139 views

Numbers to Strings in Python part 2

After implementing most of the suggestions from the first question, This is the code I got: ...
11
votes
4answers
49k views

Converting the DateTime to and from Unix epoch times

I'm currently working on a thing I needed this feature for. Essentially, these are two methods to convert DateTime objects to and from the Unix epoch time (two ...
7
votes
2answers
13k views

Converting an integer number into its word representation

I've written this code to convert an integer number into its word representation. I've tested it for many cases and it seems to be working as expected. For example: 1000 displayed as "One Thousand" ...
5
votes
2answers
221 views

Numbers to English Strings in Python3

Inspired by the recent surge of questions dealing with changing numbers to their English equivalents (See here, here, and here), I decided to write my own version in Python. ...
15
votes
4answers
2k views

Number to words in left to right direction

I have faced this question in an interview: If we enter a number it will convert into individual strings and display in same order. Ex: If I enter 564 then the ...
10
votes
1answer
198 views

Refactor VB.NET to C#.Net using Linq

I am rewriting a VB.NET application in C#. I will not subject you to the original code because it's pretty messy. Below is the converted C# code: ...
8
votes
1answer
2k views

Very simple PostgreSQL ORM in C++ using libpq

I'm working on a set of helper classes for working with libpq in C++ and I want to be able to pass in objects to the helper classes and have them internally represented as strings when sent to the db, ...
8
votes
4answers
17k views

Kelvin-Fahrenheit-Celsius temperature converter

I am curious if it would ever be in good practice to omit constructor definitions from a class. Here, the intention of the Temperature class is to simply convert between one temperature scale to ...
7
votes
4answers
1k views

Converting an integer into the written form

For my homework assignment I have to create a class which converts an integer between 0 and 9999 into the written form. For example, 713 would be written as "seven ...
6
votes
1answer
2k views

Converting a hexadecimal string to a binary string using Rust pattern matching lookup

I am getting started in Rust, and as a part of my first exercise, I decided to write a small program that converts a hexadecimal string to a binary string using a pattern matched lookup. I would ...
6
votes
4answers
947 views

Bytes to binary conversion function

I created a quick function to convert n bytes into binary for my student. She is not on that level yet, but I think it would be best for her if my demonstrative ...
6
votes
2answers
6k views

Convert Roman to Int

I made a function that converts Roman letters to integers. But I'm not happy with it, as I feel like I used too much code for a such a simple task. Any suggestion on how I can minimize it? ...
5
votes
1answer
195 views

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

I'm trying to process numerical input arguments for a function. Users can mix ints, floats, and "array-like" things of ints and float, as long as they are all length=1 or the same length>1. Now I ...
4
votes
1answer
2k views

Python converter: number-to-English - Project Euler 17

So I wrote this function to convert a given number to its interpretation in the English language as part of the Project Euler exercises. It works fine, but I sense that it's rather sloppy and ...
4
votes
1answer
1k views

Program for importing autotask contracts into dynamics CRM 2011

We regularly have to convert a bunch of autotask Contracts to a custom CRM entity because we have employees who don't work in Autotask but need those contracts. I wrote the above code to handle this ...
3
votes
1answer
122 views

Conversion Helper with support for enumerations and Nullable<T> - The Remix

I recently wrote this code as a more versatile stand-in for Convert.ChangeType. I very recently posted an earlier version, for which I received some good feedback. I've incorporated that feedback and ...
3
votes
1answer
224 views

PowerShell script binary-decimal-hexadecimal-ipv4 convertor

This is a fully functional PowerShell script I wrote not long ago that converts data (numerical data) among 4 data formats: binary, decimal, hexadecimal and ipv4. It supports 12 conversions, it can ...
2
votes
1answer
7k views

Milliseconds to Time string & Time string to Milliseconds

Fast Time conversion I'm trying to write a very fast time-to-string and string-to-time function. I noticed that on low CPU mobile devices this function has, even if minimal, impact on the ...
0
votes
2answers
2k views

Command line tool for extracting, searching, and converting

I just completed my first real application (command line app). It's simple, but I had no prior knowledge of Python. Everything was hit and miss, with many Python books and help from those in this ...
13
votes
1answer
287 views

Naming numbers in American English

This seems like a popular topic lately, so I took a crack at it. Related questions are Number to Words and Converting a number to the text representation. I used this article as a guideline. The ...
12
votes
7answers
12k views

Class for handling unit conversions

I am creating a class to be the end all defacto class for handling unit conversions. This is particularly difficult in my company's industry where imperial architectural strings are used as units. I ...
8
votes
1answer
144 views

Brainf**k to Ruby converter -- v2

Previous iteration. You know, I think this is the fastest I've ever pushed out an update to anything. This is Version 2 of my Brainf**k to Ruby converter, and the generated code looks... Well, like ...
7
votes
2answers
428 views

Brainf**k to Ruby converter, written in Ruby -- v1.0

I've seen a lot of Brainf**k interpreters in various languages. I decided that actually interpreting Brainf**k is too hard, so instead of that, I wrote a 'compiler' in Ruby that directly transcribes ...
6
votes
1answer
136 views

Bash script to convert NIST vectors to debug scripts

TL;DR: The Bash script converts a published, somewhat-structured text file into a format usable by my testing infrastructure. It's slow, I think it's ugly -- although it is fully functional. The NIST ...
6
votes
4answers
2k views

Conversion helper with support for enumerations and Nullable<T>

I recently wrote this code as a more versatile stand-in for Convert.ChangeType. I have a nagging feeling that there's something I might be overlooking, or that ...
5
votes
3answers
3k views

Python Barcode Generator

I was asked to provide some example code for a job interview and didn't have anything to offer, so wrote the following function. A barcode generator may seem a bit basic, but there's some logic behind ...
5
votes
2answers
6k views

Length Converter

I have a Swing application that converts lengths. Inches to centimeter, feet to yard, etc. I’m wondering if I could make the super large HashMap a little smaller, or more efficient. Any other ...
5
votes
3answers
644 views

Displaying TimeSpan as largest interval (with units)

The following method is used in a call center application to display an approximation of remaining time. The call center telephone operator would inform the caller that they could perform their ...
4
votes
3answers
198 views

Setting Entity Framework up for success

So I am working on an application (top-secret!) that I need settings for, these settings are pretty basic, but I don't want to make a single-row table with a bunch of serialized settings, or a single-...
3
votes
1answer
155 views

Convert a Binary Tree to Doubly Linked List

Challenge Link on geeksforgeeks: Binary Tree to DLL Given a Binary Tree (BT), convert it to a Doubly Linked List(DLL) In-Place. The left and right pointers in nodes are to be used as previous ...
3
votes
2answers
277 views

Displaying TimeSpan as largest interval (with units) - Part II

[This is a follow-up question to: Displaying TimeSpan as largest interval (with units). The code listed here has been refactored since the original question was posed. Please note that the scope of ...
3
votes
2answers
714 views

PowerShell script to convert .reg files to PowerShell commands

This is a PowerShell script I wrote a while ago that converts Windows Registry files to PowerShell commands(New-Item, Remove-Item...
3
votes
2answers
4k views

ConcurrentLinkedQueue to unmodifiable list

I have a ConcurrentLinkedQueue where I put some mails in. Now I have a visual page where I want to see what's in the Queue, but ...
3
votes
1answer
381 views

Converting an array-returning function to a lazy evaluator

Take a look at the following function: ...
2
votes
3answers
197 views

Convert carry-add loop to a map or reduce to one-liner

I want to perform standard additive carry on a vector. The base is a power of 2, so we can swap modulus for bitwise AND. ...
1
vote
1answer
75 views

ConvertAll Methods Implementation for Multidimensional Array in C# - follow-up

This is a follow-up question for ConvertAll Methods Implementation for Multidimensional Array in C#. Thanks to aepot's answer and Olivier's answer. In order to match the usage of the build-in API <...