type-conversion

PHP Object conversion question

I am converting from JSON to object and from object to array. It does not what I expected, can you explain to me? $json = '{"0" : "a"}'; $obj = json_decode($json); $a = (array) $obj; print_r($a); echo("a0:".$a["0"]."<br>"); $b = array("0" => "b"); print_r($b); echo("b0:".$b["0"]."<br>"); The output here is: Array ( [0] => a ) a0: Ar...

Casting problem cant convert from void to float C++

as i said i get this horrible error i dont really know what to do anymore float n= xAxis[i].Normalize(); thats where i get the error and i get it cuz normalize is a void function this is it void CVector::normalize() { float len=Magnitude(); this->x /= len; this->y /= len; } i need normalize to stay as void tho i tried norma...

Can't find which row is causing conversion error

I have the following table: CREATE TABLE [dbo].[Accounts1]( [AccountId] [nvarchar](50) NULL, [ExpiryDate] [nvarchar](50) NULL ) I am trying to convert nvarchar to datetime using this query: select convert(datetime, expirydate) from accounts I get this error: Conversion failed when converting datetime from character string....

Why subtract a value from itself (x - x) in Python?

In NumPy functions, there are often initial lines that do checking of variable types, forcing them to be certain types, etc. Can someone explain the point of these lines in scipy.signal.square? What does subtracting a value from itself do? t,w = asarray(t), asarray(duty) w = asarray(w + (t-t)) t = asarray(t + (w-w)) source ...

Converting string to a simple type

.Net framework contains a great class named Convert that allows conversion between simple types, DateTime type and String type. Also the class support conversion of the types implementing IConvertible interface. The class has been implemented in the very first version of .Net framework. There were a few things in the first .Net framewor...

Compatible types and structures in C

I have the following code: int main(void) { struct { int x; } a, b; struct { int x; } c; struct { int x; } *p; b = a; /* OK */ c = a; /* Doesn't work */ p = &a; /* Doesn't work */ return 0; } which fails to compile under GCC (3.4.6), with the following error: test.c:8: error: incompatible types in a...

Convert WMI CimType to System.Type

I am trying to write a generic extension to turn a ManagementObjectCollection into a DataTable. This is just to make things easier for a startup script/program I am writing. I have ran into a problem with CimType. I have included the code I have written so far below. public static DataTable GetData(this ManagementObjectCollection...

gcc, strict-aliasing, and casting through a union

Do you have any horror stories to tell? The GCC Manual recently added a warning regarding -fstrict-aliasing and casting a pointer through a union: [...] Taking the address, casting the resulting pointer and dereferencing the result has undefined behavior [emphasis added], even if the cast uses a union type, e.g.: union a_union...

Choosing a type for search results in C#

I have a result set that will never exceed 500; the results that come back from the web-service are assigned to a search results object. The data from the webservice is about 2mb; the bit I want to use is about a third of each record, so this allows me to cache and quickly manipulate it. I want to be able to sort and filter the results...

Error Handling in T-SQL Scalar Function

Ok.. this question could easily take multiple paths, so I will hit the more specific path first. While working with SQL Server 2005, I'm trying to create a scalar funtion that acts as a 'TryCast' from varchar to int. Where I encounter a problem is when I add a TRY block in the function; CREATE FUNCTION u_TryCastInt ( @Value as VARCH...

Should I go for Arrays or Objects in PHP in a CouchDB/Ajax app?

I find myself converting between array and object all the time in PHP application that uses couchDB and Ajax. Of course I am also converting objects to JSON and back (for sometimes couchdb but mostly Ajax), but this is not so much disturbing my workflow. At the present I have php objects that are returned by the CouchDB modules I use an...

Problem in type casting in NSDate to NSString?

Hi, I developing an application, in which i found a ridiculous problem in type casting, I am not able to type cast NSDate to NSString. NSDate *selected =[datePicker date]; NSString *stringTypeCast = [[NSString alloc] initWithData:selected encoding:NSUTF8StringEncoding]; From ,above snippet datePi...

Avoid incompatible pointer warning when dealing with double-indirection

Assuming this program: #include <stdio.h> #include <string.h> static void ring_pool_alloc(void **p, size_t n) { static unsigned char pool[256], i = 0; *p = &pool[i]; i += n; } int main(void) { char *str; ring_pool_alloc(&str, 7); strcpy(str, "foobar"); printf("%s\n", str); return 0; } ... is it pos...

How to retrieve a bigint from a database and place it into an Int64 in SSIS

I ran into this problem a couple years back and am hoping there has been a fix and I just don't know about it. I am using an 'Execute SQL Task' in the Control Flow of an SSIS package to retrieve a 'bigint' ID value. The task is supposed to place this in an Int64 SSIS variable but I getting the error: "The type of the value being assigned...

Why do Java and C# not have implicit conversions to boolean?

Since I started Java it's been very aggravating for me that it doesn't support implicit conversions from numeric types to booleans, so you can't do things like: if (flags & 0x80) { ... } instead you have to go through this lunacy: if ((flags & 0x80) != 0) { ... } It's the same with null and objects. Every other C-like language I kn...

silverlight TypeDescriptor.GetConverter substitute

I am trying to use the LINQtoSQL project in silverlight (its a great project), because its open sourced i figured i could just recompile as a silverlight class library but unfortunately it appears to use a feature not available in silverlight. The TypeDescriptor.GetConverter method. It uses this to find type converters to properly parse...

Retrieving the first digit of a number

Hi, I am just learning Java and am trying to get my program to retrieve the first digit of a number - for example 543 should return 5, etc. I thought to convert to a string, but I am not sure how I can convert it back? Thanks for any help. int number = 534; String numberString = Integer.toString(number); char firstLetterChar = numberStr...

Conversion between different template instantiation of the same template

I am trying to write an operator which converts between the differnt types of the same implementation. This is the sample code: template <class T = int> class A { public: A() : m_a(0){} template <class U> operator A<U>() { A<U> u; u.m_a = m_a; return u; } private: int m_a; }; int main(...

Fastest way in C# to read block of bytes from file and converting to float[]

Hi! I need a fast way in C# leanguage of converting/casting array of bytes encoding one short (int16) value for 2bytes into float representation, as fast as possible. Performance bottleneck was method: samples[sample] = (float)binraryReader.readInt16(); (huge ammount of IO calls so i had to convert to block read) Basically i have fil...

how to convert hexadecimal to byte in php

I am very new to PHP I mean I want to create a byte array something like this byte array[] = { (byte) 0x9C, (byte) 0xA0}; how to do I do it in PHP any syntactical help highly apreciated. I mean how to create a byte array in php. Thanks in advance ...