14 Reusable Code Snippet Topics
Remove Filter
|
|
This will convert a decimal number into Gray code . |
|
I work with images...a *lot*. Often this involves image processing of various types such as resizing, resampling, and various cleanup operations. However, a common issue is that people like to conflate Adobe PDF with images. As such, any application that works with images should also work with PDF. However, since … |
|
I you ever would have the need to do this conversion you probably would use `string myStr = Convert.ToString(myInt,2);` which does the job. Here is presented another way to do this with some simple formatting included. Some highlights for newbies and not so newbies: Line 9: Custom enum type Line … |
|
The computer is a binary beast. We want to go from the one-fingered digital box to the ten-fingered human being and convert binary to denary(base 10) numbers. This is how it works, for instance, binary 10010 is calculated as 1*16+0*8+0*4+1*2+0*1 = decimal 18. Just because it's easy, let's throw in … |
|
Simple conversion between string and int. |
|
We can run Python2 script in most simple cases if we just use the 2to3.py script found in recent Python versions: F:\Python27\Tools\Scripts>copy \test\output_window_tk.py \test\output_window_tk2.py 1 tiedosto(a) on kopioitu. F:\Python27\Tools\Scripts>2to3.py -w \test\output_window_tk.py RefactoringTool: Skipping implicit fixer: buffer RefactoringTool: Skipping implicit fixer: idioms RefactoringTool: Skipping implicit fixer: set_literal RefactoringTool: Skipping implicit fixer: … |
|
Here is base conversion function written to deal also with [negative bases](http://en.wikipedia.org/wiki/Negative_base). Not yet balanced ternary, where numbers themselves can be negative, maybe later I add it.. Based on the code in the wikipedia article, which has bug for converting 0.[**Edit: I fixed the bug in wikipedia**] |
|
The need for efficient storing of IP numbers came up in discussion thread. With help of this conversion to/from the 32 bit numbers that IP numbers (the old ones) represent I could push the time of finding unique IP numbers from 10 million random numbers down to under two minutes … |
|
Although [url=http://en.wikipedia.org/wiki/Roman_numerals]roman numerals[/url] sneak in our lives from time to time, we(luckily) don't use them very often. Probably the reason why the Romans where not that good at calculating things. That changed, more than 1000 years later, with [url=http://en.wikipedia.org/wiki/Fibonacci]this person[/url] who introduced to the Western world the number system we … |
|
There was little buggy version of Python base conversion around, so here quick hack for my own program, including test with random numbers to verify it. |
|
Convert a decimal (denary) integer to a binary string. An exercise in do ... while and while loops. |
|
Here's a function that manually converts an integer to any base between 2 and 36, the parameter list is: [CODE]void toBase( int value, // Integer value to convert char *target, // Pointer to a large enough buffer int base, // Base (from 2 to 36) int fixedDigitCount // The minimum … |
|
Class to convert between Celcius, Fahrenheit and Kelvin temperatures. Set one temperature and automatically get the other two. This class makes use of properties. See the code snippet for details. A short main program is added to exercise the Temperature class by printing a conversion table between celsius and fahrenheit. |
|
If you have to convert an angle from degrees to radians and way back, here are some utility functions in C#, along with a program to test them. I made use of the "out" keyword here, which allows a function to return more than one value. An alternative would be … |
The End.