conversion

How to convert an IPv4 address into a integer in C#?

I was going to attempt to write this function myself but I thought that someone on SO might know the answer :) I'm basically looking for a function that will convert a standard IPv4 address into an Integer. Bonus points available for a function that will do the opposite. Solution should be in C#.net. ...

Most efficient way to convert BCD to binary

I have the code below to convert a 32 bit BCD value (supplied in two uint halves) to a uint binary value. The values supplied can be up to 0x9999, to form a maximum value of 0x99999999. Is there a better (ie. quicker) way to achieve this? /// <summary> /// Convert two PLC words in BCD format (forming 8 digit number) into sin...

Is possible to cast a variable to a type stored in another variable?

This is what I need to do: object foo = GetFoo(); Type t = typeof(BarType); (foo as t).FunctionThatExistsInBarType(); Can something like this be done? ...

Gluing (Imposition) PDF documents

I have several A4 PDF documents which I would like (two into one) "glue" together into A3 format PDF document. So I will get from 2PDFs A4 a single one sided PDF A3. I have found the excellent utility PDFToolkit and some others but none of them can be used to "glue" side by side two documents. ...

How do display the Integer value of an IPAddress

I was looking at the System.Net Namespace and it has an IPAddress instance you can use. This has a Parse method which you can use to parse a string into an IPInstance then use the Address property to give you the long value. However... The number returned is NOT the true conversion. e.g. For IP 58.0.0.0 , the System.Net namespace give...

Convert unix timestamp to julian

How can I convert from a unix timestamp (say 1232559922) to a fractional julian date (2454853.03150). I found a website ( http://aa.usno.navy.mil/data/docs/JulianDate.php ) that performs a similar calculation but I need to do it programatically. Solutions can be in C/C++, python, perl, bash, etc... ...

How do I convert a PDF document to a preview image in PHP?

Our environment is a LAMP stack. I'm wondering what libraries/extensions etc. would be required to convert a portion of a PDF document into an image file? Most PHP PDF libraries that I have found center around creating PDF documents, but is there a simple way to render a document to an image format suitable for displaying on a web page...

CSS 2.1 compliant HTML to Microsoft Word conversion?

I've found a superb HTML to PDF converter in Prince XML. Now I'm looking for something of similar quality to produce Word documents from HTML + CSS. This is on PHP/Linux. ...

Ffmpeg and Xing header - iTunes issue and Duration issue

Hello all, I extract the audio from a bunch of flv files as an MP3. This works great: ffmpeg -i video.flv -vn -acodec copy audio.mp3 However, some audio that I extract have durations that are longer than they should be and some MP3 files keep looping the audio! Also in some audio players like WMP, the seekbar gets stuck at one point....

Floating Point to Binary Value(C++)

I want to take a floating point number in C++, like 2.25125, and a int array filled with the binary value that is used to store the float in memory (IEEE 754). So I could take a number, and end up with a int num[16] array with the binary value of the float: num[0] would be 1 num[1] would be 1 num[2] would be 0 num[3] would be 1 and so o...

Performance of enum conversion

Hi folks, after a bit speedtracing I found a piece of code (called very very often) which converts values of one enum to values of another enum, like this: public Enum2 ConvertToEnum2(Enum1 enum1) { switch(enum1) { case Enum1.One: return Enum2.One; break; case Enum1.Two: return Enum2.Two; ...

New to Java - Converting to Binary, Counting 1's, Recursive

Hey Everyone I just started Data Structures and Algorithms which is taught in Java. So far I've only learned C++ in my life so I'm still VERY new to using java. Anyways I have a homework problem I'm a little stuck on: Write a recursive method that returns the number of 1's in the binary representation of N. Use the fact that this is e...

Is this code snippet from Java to c# correct?

Hi folks, i'm trying to port some Java stuff to C#. I'm just wondering if the following C# code is the equivalent to the original Java source. Source: Java Code private static final Pattern SIMPLE_IDENTIFIER_NAME_PATTERN = Pattern.compile("^[a-zA-Z_][a-zA-Z0-9_]*$"); private static boolean isValidIdentifier(String s) { ...

How do I convert a DataTable to an IDatareader?

We all know that DataReaders are quicker than DataTables since the a DataReader is used in the construction of a DataTable. Therefore given that I already have a DataTable.... Why would I want to convert it to a DataReader? Well I am creating an internal interface called IDataProvider. This interface is intended to be implemented both ...

How do you convert LOGFONT.lfHeight to pixels?

I have a LOGFONT.lfHeight value of -11. However, I know that the font size is actually 8 so do I need to convert this number to a different unit of measurement? I found this formula in the MSDN docs: int height = abs((pixels * DOTSY) / 72); This takes pixels and makes it into a height value that LOGFONT can use. If I work this the othe...

Convert List(of object) to List(of string)

Is there a way to convert a list(of object) to a list(of string) in c# or vb.net without iterating through all the items? (Behind the scenes iteration is fine - I just want concise code) Update: The best way is probably just to do a new select myList.Select(function(i) i.ToString()) or myList.Select(i => i.ToString()); ...

Converting some LISP to C#

I'm reading Paul Graham's A Plan for Spam and want to understand it better but my LISP is really rusty. He has a snippet of code that calculates probability as such: (let ((g (* 2 (or (gethash word good) 0))) (b (or (gethash word bad) 0))) (unless (< (+ g b) 5) (max .01 (min .99 (float (/ (min 1 (/ b nbad)) ...

How do I convert a string to a double in Python?

I would like to know how to convert a string containing digits to a double. ...

Type Conversions in Ruby: The "Right" Way?

I am trying to decide if a string is a number in Ruby. This is my code whatAmI = "32.3a22" puts "This is always false " + String(whatAmI.is_a?(Fixnum)); isNum = false; begin Float(whatAmI) isNum = true; rescue Exception => e puts "What does Ruby say? " + e isNum = false; end puts isNum I realize that I can do it with a RegEx, ...

SoX wav sound playback

I tried this: sox -u -r 11.025k -b 8 -c 1 infile.wav outfile.wav but the sound is garbled and unrecognizable when I play it. Help? ...