type-conversion

Issues with reversing bit shifts that roll over the maximum byte size?

I'm trying to do a simple caesarian shift on a binary string, and it needs to be reversable. I've done this with this method.. public static String cShift(String ptxt, int addFactor) { String ascii = ""; for (int i = 0; i < ptxt.length(); i+=8) { int character = Integer.parseInt(ptxt.substring(i,...

C# .NET 4.0 and Generics

I was wondering if anyone could tell me if this kind of behaviour is possible in C# 4.0 I have an object hierarchy I'd like to keep strongly typed. Something like this class ItemBase {} class ItemType<T> where T : ItemBase { T Base { get; set; } } class EquipmentBase : ItemBase {} class EquipmentType : ItemType<EquipmentBase> {}...

Java conditional operator ?: result type

I'm a bit puzzled about the conditional operator. Consider the following two lines: Float f1 = false? 1.0f: null; Float f2 = false? 1.0f: false? 1.0f: null; Why does f1 become null and the second statement throws a NullPointerException? Langspec-3.0 para 15.25 sais: Otherwise, the second and third operands are of types S1 and S2...

How does the CLR know the type of a boxed object?

When a value type is boxed, it is placed inside an untyped reference object. So what causes the invalid cast exception here? long l = 1; object obj = (object)l; double d = (double)obj; ...

How to convert a gi-normous integer (in string format) to hex format? (C#)

Given a potentially huge integer value (in c# string format), I want to be able to generate it's hex equivalent. Normal methods don't apply here as we are talking arbitrarily large numbers, 50 digits or more. The techniques I've seen which use a technique like this: // Store integer 182 int decValue = 182; // Convert integer 182 as a he...

Convert float to decimal in Informix

I have a table with a column of type decimal. There is a ESQL/C structure that represents the table. It has a member of type decimal. I also have a normal C structure for equivalent for the same table. The type of the above mentioned field is a float. Since we use memcpy to copy data to and from ESQL/C structure to C structure, there is...

Constructor Type Coercion in C++

Take the following class: class mytype { double num; public: mytype(int a) { num = sqrt(a); } void print() { cout << num; } } Say there is a method which takes a mytype: void foo(mytype a) { a.print(); } Is it legal c++ (or is there a way to implemen...

How to combine Option values in Scala?

Hi! I want to be able to apply an operation f: (T,T) => T to Option[T] values in Scala. I want the result to be None if any of the two values is None. More specifically, I want to know if is there a shorter way to do the following: def opt_apply[T](f: (T,T) => V, x: Option[T], y: Option[T]): Option[T] = { (x,y) match { case (Som...

serializing type definitions?

I'm not positive I'm going about this the right way. I've got a suite of applications that have varying types of output (custom defined types). For example, I might have a type called Widget: Class Widget Public name as String End Class Throughout the course of operation, when a user experiences a certain condition, the applic...

Is this an edge case in PowerShell's type resolution mechanism?

Here's my situation. I have a PowerShell module which imports the PowerShell-JSON library; this library converts JSON strings into PowerShell objects. My module provides an interface to CouchDB, so my JSON strings are obtained from HTTP calls. I have a function, Send-CouchDbRequest, which makes the HTTP request to CouchDB and returns ...

Why does Python Array Module Process Strings and Lists Differently?

I'm having trouble understanding the result of the following statements: >>> from array import array >>> array('L',[0xff,0xff,0xff,0xff]) array('L', [255L, 255L, 255L, 255L]) >>> from array import array >>> array('L','\xff\xff\xff\xff') Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: string length ...

Can a single argument constructor with a default value be subject to implicit type conversion

I understand the use of the explicit keyword to avoid the implicit type conversions that can occur with a single argument constructor, or with a constructor that has multiple arguments of which only the first does not have a default value. However, I was wondering, does a single argument constructor with a default value behave the same...

Converting an int64 value to a Number object in JavaScript

I have a COM object which has a method that returns an unsigned int64 (VT_UI8) value. We have an HTML page which contains some JavaScript which can load the COM object and make the call to that method, to retrieve the value as such: var foo = MyCOMObject.GetInt64Value(); This value can easily be displayed to the user in a message dia...

"Invalid use of Null" when using Str() with a Null Recordset field, but Str(Null) works fine

I'm banging my head against the wall on this one. I was looking at some old database reporting code written in VB6 and came across this line (the code is moving data from a "source" database into a reporting database): rsTarget!VehYear = Trim(Str(rsSource!VehYear)) When rsSource!VehYear is Null, the above line generates an "Invalid us...

Convert from vector of arrays to one array

I have a vector of float arrays i.e. Vector . I want to convert this to one float array i.e. move every element in every float[] within the vector to a new float[]. Am a bit puzzled on using the Java built in method vector.toArray() to do this. Any ideas pls? ...

C# string to combobox issues

What i'm trying to do is read in a header row of a file to a combobox. Here is my code: private void button4_Click(object sender, EventArgs e) { string[] startdelim = File.ReadAllLines(textBox1.Text); int counter = 1; foreach (string delim in startdelim) { if (counter == 1) { string removed...

C#: Determine Type for (De-)Serialization

Hi, i have a little problem implementing some serialization/deserialization logic. I have several classes that each take a different type of Request object, all implementing a common interface and inheriting from a default implementation: This is how i think it should be: Requests interface IRequest { public String Action {get;set;...

Type result with Ternary operator in C#

I am trying to use the ternary operator, but I am getting hung up on the type it thinks the result should be. Below is an example that I have contrived to show the issue I am having: class Program { public static void OutputDateTime(DateTime? datetime) { Console.WriteLine(datetime); } public static bool IsDateT...

Can anybody explain to the meaning of this expression ??

void* GetData() { return reinterpret_cast<unsigned char*>(this); } Is there a case of automatic type coercion happening in this case ??? How could I convert the object of my class to an unsigned char* ?? ...

Need help in typecasting string in to int

I am using Convert.ToInt32(ddlBuyer1Country.SelectedValue); to typecast a string returned by selectedvalue. But this is giving me 0 instead of 3. I have selected value as 3 in this case. ...