FAQ Database Discussion Community


Is there any way to convert an array to class properties?

php,arrays,class,object,type-conversion
There is a way to get class properties and convert it using (array) casting. $user = (array) get_object_vars($userObject) But I wonder, I didn't find any direct method to convert array to class properties. Suppose I have user class with following implementation: class User { private $id = 0; private $fname...

type-conversion in one function in C

c,function,struct,type-conversion,typedef
I have one doubt, could it be possible to create one typedef struct whatever and then if one function requires: void function(char * something); when you call the function in main program write: function((char *) whatever); is that correct? Thank you!...

Convert CLLocationCoordinate2D to double or int swift

swift,int,type-conversion,cllocationcoordinate2d
how would I convert a CLLocationcoordiante to a double so that I can perorrm arithmetic on it and compare coordinates using their size? In (swift for ios)

how to convert date time if passing null value in date field

c#,asp.net,type-conversion,nullable
How to store null value and how to insert null values in database? im getting this error. String was not recognized as a valid DateTime. if (taskObj.EstimatedTime == null) { taskObj.EstimatedTime = Convert.ToDateTime(estimateTimeLabel.Text); } public DateTime EstimatedTime { set { estimatedTime = value; } get { return estimatedTime; } }...

Simple and clean java float to string conversion

java,string,floating-point,formatting,type-conversion
This is a very simple question, but I'm amazed on how difficult it has been to answer. Even the documentation didn't give a clear and straight answer. You see, I'm simply trying to convert a simple float to a string such that the result only has one decimal digit. For...

Converting INT to Hours and Minutes in SQL

php,mysql,sql,type-conversion
I need to convert and INT such as 125, to hours and minutes which will be 02:05. I know I can do this in PHP with the following: date('H:i',mktime(0, 125)) but how do I do this in SQL? I tried SEC_TO_TIME(table.minutes*60) which works but this results in 02:05:00 and I...

how I get a number outside [0,255] when doing a converson from int to char?

c++,char,type-conversion
I do not see why conversion from int to char gives me a number outside the range of (char)? Here is my C++ program: #include <cmath> #include <stdio.h> int main(){ printf("%c\n",(char) 246 ); printf("%d\n", (char) (246) ); } I get \366 -10 Any explanation? What I need here is a...

Converting binary data to .doc file with the images inside it

c#,sql,.net,type-conversion,binary-data
I have binary data stored in database which I need to convert them back for backup purposes. Most of them are .doc files with images attached in document. My method to restore them is to write binary data to byte string and write those bytes to the file like mydoc.doc....

Haskell length toInteger Conversion

haskell,integer,int,type-conversion,tuples
I have the following pair of Integers: maxCollatz :: (Integer, Integer) maxCollatz = (head $ maximum (map collatzList [1..500]), length $ maximum (map collatzList [1..500])) Since I am a newbie, I don't know how to use either fromIntegral or toInteger to convert length to Integer. I know that length must...

C++ char* to HEX conversion

c++,hex,type-conversion
I want to convert byte data (file body) to hex in order to print it. I've copied a function for conversion, but not exactly understand it. #include "stdafx.h" #include <iostream> #include <Windows.h> #include <string> std::string byte_2_str(char* bytes, int size) { char const hex[16] = { '0', '1', '2', '3', '4',...

Converting from __m128 to __m128i results in wrong value

c++,type-conversion,clang,sse,intrinsics
I need to convert a float vector (__m128) to an integer vector (__m128i), and I am using _mm_cvtps_epi32, but I am not getting the expected value. Here is a very simple example: __m128 test = _mm_set1_ps(4.5f); __m128i test_i = _mm_cvtps_epi32(test); The debugger output I get: (lldb) po test ([0] =...

Why does StringBufferInputStream doc recommend StringReader for String to Stream conversion?

java,string,type-conversion,inputstream
As has been answered repeatedly, you can easily convert a String to an InputStream. When browsing the Java 8 documentation I came across the long-deprecated StringBufferInputStream class, which states that As of JDK 1.1, the preferred way to create a stream from a string is via the StringReader class. What...

Fastest Possible Struct-of-Arrays to Array-of-Structs Conversion

c++,arrays,struct,type-conversion
I have a structure that looks like this: struct SoA { int arr1[COUNT]; int arr2[COUNT]; }; And I want it to look like this: struct AoS { int arr1_data; int arr2_data; }; std::vector<AoS> points; as quickly as possible. Order must be preserved. Is constructing each AoS object individually and pushing...

Getting bit-pattern of bool in Swift

swift,int,boolean,type-conversion,bit-manipulation
In ObjC, a bool's bit pattern could be retrieved by casting it to a UInt8. e.g. true => 0x01 false => 0x00 This bit pattern could then be used in further bit manipulation operations. Now I want to do the same in Swift. What I got working so far is...

Cannot convert type via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion

c#,interface,type-conversion
In C#, if I have a parameter for a function where the parameter type is of an interface, how do a pass in an object that implements the interface. Here is an example: The parameter for a function is as follows: List<ICustomRequired> The list that I already have is as...

Integer to custom type conversion in Ada

indexing,types,integer,type-conversion,ada
I have an array of some kind of objects, indexed by a type index: type index is new Integer range 1..50; type table is new Array(index) of expression; Now, I need to access one of these expressions, depending on a user entry by keyboard. For that I do following: c:...

How to convert interface{} to bytes.Buffer

go,type-conversion
How to convert interface{} to bytes.Buffer? Minimal example package main import ( "bytes" "fmt" ) func ToJson5(any interface{}) string { if any == nil { return `''` } switch any.(type) { case bytes.Buffer: // return as is return any.(bytes.Buffer).String() // other types works fine } return `` } func main()...

How can I convert an Int array into a String? array in Swift

ios,arrays,swift,casting,type-conversion
I have an array that looks like this: var arr: [Int] = [1,2,3,4,5] In order to print this, I would like to convert this to: var newArr: [String?] = ["1","2","3","4","5"] Please help me out! Thanks in advance....

Confusion with Kotlin generics

java,generics,types,type-conversion,kotlin
I'm new to Kotlin and I'm trying to write code which does something fairly simple, however I cannot figure out how to use generics to get it to work. I have a Handler trait which represents a handler for things. I cannot change the code for a Handler as it...

Recursive function to convert string to integer in C

c,string,recursion,type-conversion,decimal
I have the following working code; it accepts a string input as the function parameter and spits out the same string converted to a decimal. I'm not going to bother accounting for negative inputs, although I understand that I can set a boolean flag to true when the first indexed...

Making a convenient logging function for Try[T], but got stuck because of the type system

scala,casting,type-conversion,scala-generics
I wonder if this can be done using Scala's type system. Basically, I want to make a logging method which accepts a result of type Try[T] and prints out a message that differs a bit depending whether result is a Success or a Failure For example, the signature might look...

Java method invocation conversion

java,type-conversion,method-invocation
Hello I reading about java types conversion, so I found in the book Java Language Specification made by Oracle this quote : Method invocation conversion is applied to each argument in a method or constructor invocation and, except in one case, performs the same conversions that assignment conversion does. So...

User input to check a DNA sequence for restriction sites with BioPython

python,type-conversion,biopython
I wish to write a script that accepts a user inputted restriction enzyme name (therefore a string) and parses a given DNA sequence (also a string) for instances of the restriction enzyme sequence. The input would access the library of restriction enzymes contained in the Bio.Restriction module. A very simple...

Convert IntPtr to char** in C#

c#,memory-management,types,type-conversion,dllimport
I'd like to interpret the output of the following unmanaged function: afc_error_t afc_get_device_info (afc_client_t client, char ***device_information) I import the dll with the code: [DllImport("libimobiledevice.dll", CallingConvention = CallingConvention.Cdecl)] internal static extern short afc_get_device_info(IntPtr client, out IntPtr info); As long as I only needed to convert response to string Marshal.PtrToStringAnsi was...

PHP class constants seems to always be interpreted as strings

php,type-conversion,class-constants
A class constant always seems to be interpreted as a string although it is defined as an integer. Why does PHP do this kind of type juggling and how do I prevent it? See the following code: class BitSet { const NONE = 0; const FOO = 1; const BAR...

What is the best way to convert Dollars (Big Decimal) in Cents (Integer) in java?

java,integer,type-conversion,bigdecimal
I have to integrate my web application with a payment gateway. I want to input total amount in USD and then convert it into Cents as my payment gateway library accepts amount in Cents (of type Integer). I found that Big Decimal in java is best way for manipulation of...

How can I convert Int32 to Int in Swift?

swift,core-data,int,type-conversion
It should be easy but I can only find the reverse conversion. How can I convert Int32 to Int in Swift? Unless the problem is different? I have a value stored in Core Data and I want to return it as an Int. Here is the code I am using,...

Overloading Assignment operator in template based class

c++,templates,type-conversion,operator-overloading,template-meta-programming
I am writing a library to support a type of integers which have two template parameters INT_BITS and FRAC_BITS. I was successful in writing a convert function to convert different class types from one to another [ which vary in values of INT_BITS and FRAC_BITS ]. But when I try...

Float must be a string or a number?

python,type-conversion,text-files
I have a very simple program. The code: money = open("money.txt", "r") moneyx = float(money) print(moneyx) The text file, money.txt, contains only this: 0.00 The error message I receive is: TypeError: float() argument must be a string or a number It is most likely a simple mistake. Any advice? I...

Python: ValueError: could not convert string to float:

python-2.7,type-conversion,python-requests
I get a Typecast - Error, when I try to convert unicode-strings, parsed from a website. Here are the relevant codebits: # special IPython command to prepare the notebook for matplotlib %matplotlib inline from fnmatch import fnmatch import numpy as np import pandas as pd import matplotlib.pyplot as plt import...

Java: Efficiently converting an array of longs to an array of bytes

java,arrays,type-conversion,long-integer,endianness
I have an array of longs I want to write to disk. The most efficient disk I/O functions take in byte arrays, for example: FileOutputStream.write(byte[] b, int offset, int length) ...so I want to begin by converting my long[] to byte[] (8 bytes for each long). I'm struggling to find...

Convert const char* to const wchar_t*

c++,type-conversion
I am trying to create a program with Irrlicht that loads certain things from a configuration file written in Lua, one of which is the window title. However, the lua_tostring function returns a const char* while the Irrlicht device's method setWindowCaption expects a const wchar_t*. How can I convert the...

how to convert bool array to char variable

c#,char,boolean,type-conversion
I have a boolean array which holds some values that represent ASCII value: bool[] myBoolReceived = new bool[8]; I try to convert it to a char so I can add it to a list that holds chars. myReceivedMessage = new List<char>(); I tried to use Convert.ToChar method but it not...

String is considered 'bool' after TryParse to int

c#,type-conversion,tryparse
I'm trying to convert a text input into an int that I can multiply and display the product, but whenever I try to parse the textbox contents as int, I get the "cannot convert bool to int" error message. Code is as follows: private void button2_Click_1(object sender, EventArgs e) {...

Redundant type conversion

c#,type-conversion
In a code example: int age; ... age = (int)Convert.ToInt32(Console.ReadLine()); I see no point to put (int) before conversion. Can I safely remove it to: age = Convert.ToInt32(Console.ReadLine()); There are the same cases, such as: height = (double)Convert.ToDouble(Console.ReadLine()); ...

Input a letter to 'int'

c++,type-conversion
Code: int a; cin>>a; cout<<a<<endl; Then I use g++ test.cpp, and run it. Then I input a letter 'b' to the variable a. The output is 0. But, When I test the Other code: cout<<int('b')<<endl; // output: 98 Why? What is the different?...

Python: tuple assignment while at same time converting type

python,floating-point,type-conversion,tuples
I'm reading tab separated values from strings into an object like this: class Node(rect): def __init__(self, line): (self.id, self.x1, self.y1, self.x2, self.y2) = line.split('\t') That works fine, but say I want to convert those x and y coordinates, which are read from the string line, to floats. What is the...

What are the values that appear at the address bar?

php,web,hex,type-conversion,translate
I am working on a webiste that translates an input string from Japanese to English. This webiste has two text fields and one button to submit the string for translation. But when I hit the button, I can see some kind of hexadecimal values separated by % in the address...

Preserving leading 0's in string - number - string conversion

string,excel,vba,excel-vba,type-conversion
I am working on a macro for a document-tracking sheet at work. I use a button that prompts the user to enter in the document number and I'd like to specify a default number based on the following numbering convention. The first two characters of the document number are the...

Converting jpeg to byte[], then inserting into SQL table

c#,sql-server,database,webforms,type-conversion
I'm trying to convert a jpeg that I select from my disk into a byte array, then insert it into a table in SQL Server. I don't receive any errors, the record just isn't inserted... I'm using a webform that allows you to select a Scheme code and Version from...

Converting images from RGB to HSL and back again with julia

image,colors,type-conversion,julia-lang,color-space
I have been trying to open some RGB images, view the data as a 2D array of HSL pixels, manipulate pixels in HSL space, convert back to RGB and write manipulated image to file. However I don't quite understand how the conversions in the (awesome) julia packages Color and Images...

Is there something in R for automatic conversion of column( of data frame or table) into its original vector type

r,csv,type-conversion
Actually i am worrying about the data, how it comes, in different vector types. Some columns are originally of type integer or numeric but are displayed as character type. If i read a data frame by read.csv(), it guesses which type of vectors and automatically converts them. I could not...

Multiple typecasting in a single line in Java program

java,casting,type-conversion
While messing around with Java syntax today, I tried to compile the following piece of java code: class Mess { public static void main(String[] args) { float i = (char)(int)(long)(byte) 100; System.out.println(i); } } The code actually gave no compilation or runtime errors. Changing data type of i to any...

How to convert from Int64 to hex and from hex to byte in c#

c#,hex,type-conversion,byte,int64
I am trying to send a byte array to micro controller over serial port. This is an example array which can successfully communicate with micro controller: byte[] getCommandArray = new byte[7] { 0x02, 0x0D, 0x01, 0x03, 0x30, 0x44, 0x03 }; What I need to do is read different values from...

Converting struct to int and vice versa

c,generics,type-conversion,c11
In order to make some _Generic expressions work properly, it appears that the only option is to convert integer types to structure types and vice versa, with these meaningless conversions only ever being present in non selected expressions. I am having trouble definitively answering the question as to whether or...

Add Column to DataTable before exporting to Excel file

vb.net,excel,datatable,type-conversion,dataview
I have a DataTable that is built like this: Dim dt As New DataTable() dt = SqlHelper.ExecuteDataset(connString, "storedProcedure", Session("Member"), DBNull.Value, DBNull.Value).Tables(0) Then it is converted to a DataView and exported to Excel like this: Dim dv As New DataView() dv = dt.DefaultView Export.CreateExcelFile(dv, strFileName) I want to add another column...

Java char is also an int?

java,type-conversion,equivalence
I was trying to get some code done for class: public int getValue(char value) { if (value == 'y') return this.y; else if (value == 'x') return this.x; Since I might not be able to return anything in the end, it told me to do this at the end: return...

Const vs. array-to-pointer conversions

c++,arrays,type-conversion,const,language-lawyer
Is the handling of constness in fa being turned inside out intentional, or does it look like a bug (compiler or the standard)? I can see how this can happen, but it still feels pretty weird (at the very least I would expect a = "qwe" to be treated as...

Comparison between unsigned int and int without using cast operator

c,int,compare,type-conversion,unsigned-integer
everyone I looked aroud there exist an topic about my question. I could not find . unsigned int x = 5; int y = -3; if(y<x) func1(); else func2(); func2 is called . But i want to call func1 . I know that, I must use cast operator by using...

What does rank mean in relation to type conversion?

c++,type-conversion,implicit-conversion,data-type-conversion,rank
From C++11 standard (draft n3337) §5/9: — If both operands have the same type, no further conversion is needed. — Otherwise, if both operands have signed integer types or both have unsigned integer types, the operand with the type of lesser integer conversion rank shall be converted to the type...

mysql select query gives result where ID (a number) is equal to text

mysql,sql,type-conversion
I have a table _users with a field id as bigint(24). The result of this query: SELECT * FROM `_users` WHERE `id`='5text' is the row with id = 5. I would expect no result since '5text' is not a number. How is this possible?...

Convert string to mpz_t in C

c,string,type-conversion,gmp
Is there a method to convert a string, or in my case a char array, to the mpz_t type from gmplib. Is there something similar to the sscanf function? Anything for the C programming language would be relevant.

Passing ReportParameters back to method

c#,type-conversion,rdl
I have an application that is doing all of our reporting with locally stored RDLs. I have two forms, one is a simple viewer that contains a TabPageControl, and the other is an FLP of controls that the user can use to select report parameters. We are planning on having...

Converting string to date in sql

sql,oracle,date,type-conversion,timestamp-with-timezone
I need to convert 2014-11-18T14:08:43+00:00 which is in varchar in my sql developer to date format in order to filter a few entries. I tried to_date(LAST_UPDATE_DATE,'YYYY-MM-DD') but it gives an error ORA-01830: date format picture ends before converting entire input string. Kindly help.....

Conversion from derived class to it's base class is widening? Why?

c#,type-conversion
According to page https://msdn.microsoft.com/en-us/library/k1e94s7e.aspx conversion from derived class to it's base class is widening. I thought that this is opposite: it's narrowing conversion. because base class object is a part of derived class's object. How to explain this in detail that this is widening conversion?...

Calculating execution time using boost::chrono

c++,boost,type-conversion,global-variables
I tried to calculate the sum of a function execution time in a loop but something goes wrong : #include <boost/chrono.hpp> #include <iostream> boost::chrono::milliseconds sumGlobal; int main() { boost::chrono::high_resolution_clock::time_point t1 ; boost::chrono::high_resolution_clock::time_point t2 ; for (i=0;i<10;i++) { t1 = boost::chrono::high_resolution_clock::now(); f(); //to waste time t2 = boost::chrono::high_resolution_clock::now(); sumGlobal +=...

Example code detailing difference in typing between Ada and Java [closed]

java,type-conversion,ada
I'm trying to think of a good example detailing the difference between Ada's strict typing and Java's strong typing. Does anyone have a good example for identifying these differences in type conversion using integer based values?

How do I get seconds from Epoch Time in MATLAB?

matlab,time,type-conversion,epoch
I have a data that are being recorded and the time is used in epoch. I want to draw a figure where the x axis from zero to the time that the recorder stopped recording in seconds. From my search I found that the output for decoding is a string...

Why does increment using ++ work with strings in javascript?

javascript,type-conversion,increment,unary-operator
Normally when I get the value of a form input with jQuery I am obliged to convert it to a number before performing any mathematical operations. For instance, using the unary plus operator to convert, and then increment: var x = +$(this).val(); x += 1; But for some reason ++...

Swift: How to convert String to UInt?

string,swift,type-conversion,uint
According to Swift - Converting String to Int, there's a String method toInt(). But, there's no toUInt() method. So, how to convert a String to a Uint?...

Binary operator '|' cannot be applied to operands of type 'Int' and 'UInt8'

swift,binary,type-conversion,unsigned-integer
I wish to perform simple or logic on 2 bit maps, yet Swift thinks this is wrong: let u: UInt8 = 0b1 let i: Int = 0b10 i | u // Binary operator '|' cannot be applied to operands of type 'Int' and 'UInit8' Any way to conform to type...

How to convert a dataframe into a gstat object in R? Specifically a gstatVariogram

r,type-conversion,geospatial,gstat,covariogram
I'd like to create a variogram fit from some semivariance data in R. I realize that a variogram fit requires an object generated by vgm, and raw.vgm gneerated by variogram, for example: x = seq(0,300,by=300/100) y = seq(0,0.9,by=(0.9/100)) Z = seq(0.0,10.0,by=(10/100)) raw.dat = data.frame(x=x,y=y,Z=Z) g <- gstat(formula=Z~1, locations=~x+y, data=raw.dat) raw.vgm...

String to Double Conversion (Comma to dot issue)

c#,xml,wpf,silverlight,type-conversion
Struggling with the basics - I'm trying to code a simple currency converter. The XML provided by external source uses comma as a decimal separator for exchange rate (kurs_sredni): <pozycja> <nazwa_waluty>bat (Tajlandia)</nazwa_waluty> <przelicznik>1</przelicznik> <kod_waluty>THB</kod_waluty> <kurs_sredni>0,1099</kurs_sredni> </pozycja> I already managed to load the data from XML into a nifty list of...

Converting a List within a List from String to Integers

python,type-conversion,python-3.4
After approximately eight hours of searching and attempting to implement solutions, I am still vexed by this problem. I am attempting to make a dinky ANOVA package that can read data from a text file, count the number of participants based on lines within said file, and then run an...

how to return a number with 2 decimal places all the time from a function

javascript,random,numbers,type-conversion
I have a random number generator function that returns a random number. It looks like the problem is that sometimes it returns only one decimal place the, tenths place(i think it's called). I always want it to output a number with 2 decimal places (some times i would get 10.5...

Is there any performance decrease in java, for extending classes for “no” reason?

java,type-conversion,jvm-hotspot,hungarian-notation
I have a Vector3i class that is useful in a lot of situations, but I've found myself extending it to use the type system to prevent bugs. For example, I might have an "ego-centric" vector3i that is local to an object in the world, and a world co-ordinate vector3i. The...

MISRA C 2004 10.1, signedness of printf “%x”

c,printf,type-conversion,format-specifiers,misra
I'm getting errors from our static analysis tool about the following snippet: uint8_t value = 24U; char buffer[512]; int chars_printed = snprintf(buffer, sizeof(buffer), "The value in hex is 0x%02hhX\r\n", value); The error is: MISRA-2004 Rule 10.1 violation: implicitly converting a non-constant expression in a function argument. Converting "value", with underlying...

How can I concatenate two bytes in java?

java,type-conversion,byte,bytearray,bucket
I have an integer called writeLocation that takes a value between [0,1023]. I need to store it in the last two bytes of a byte array called bucket. So, I figure I need to represent it as a concatenation of the array's last two bytes. How would I go about...

Why can't I cast an object-var of a long to a double?

c#,casting,type-conversion
I'm new to C# (but I know C++, JavaScript and Java) and I'm using JSON.net to parse a JSON file to a Dictionary<string, object>. Now I'm trying to store a value which was parsed as a long into a double variable. (I looked at the inspector and it says the...

convert chan to non chan in golang

go,type-conversion
Is it possible to let function funcWithNonChanResult have the following interface: func funcWithNonChanResult() int { And if I want it to use function funcWithChanResult with the interface: func funcWithChanResult() chan int { In other words, can I somehow convert chan int to int? Or I must have chan int result...

operators in predicate as argument in lambda expression

java,lambda,type-conversion,java-8,predicate
I need to use Predicate as argument in lambda expression. I tried an example code but seeing compiler error. I see that the compiler is treating the same Predicate differently for different arguments. So Predicate arguments n -> true and n -> false works but n -> n%4 == 0...

byte to int type conversion network application

java,c,casting,network-programming,type-conversion
I'm sending from my android phone integer as byte with the following code(I put only the needed chunks): private byte[] intToByteArray ( final int i ) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); dos.writeInt(i); dos.flush(); return bos.toByteArray(); } //thread sender data = new byte[16];...

Powershell throws conversion exception when trying to use SMO.Backup.AddDevice

sql,powershell,type-conversion,smo,database-restore
I'm completely confused by this one. I'm trying to write a simple database restore script using SMO assemblies. When I try to add a device and pass the path, like this: $backup.Devices.AddDevice($path, [Microsoft.SqlServer.Management.Smo.DeviceType]::File) I get an odd exception: Cannot convert argument "1", with value: "File", for "AddDevice" to type "Microsoft.SqlServer.Management.Smo.DeviceType":...

R: Convert a Character to a timestamp

r,datetime,type-conversion
Currently we are implementing some sort of direct marketing We send an SMS (timestamp) on a certain day from a certain country within Europe and then receive a response from a customer in the local country if they are interested in the product I have a sample data set for...

How to change a float64 number to uint64 in a right way?

go,floating-point,type-conversion,floating-point-conversion
package main func main() { var n float64 = 6161047830682206209 println(uint64(n)) } The output will be: 6161047830682206208 It looks like that when float64 change to uint64, the fraction is discarded....

double to int conversion not working using math.h functions in c

c,int,double,type-conversion,math.h
dataBuf[1] = acos(0.130f); This is the code I'm running but when I print out the result, it comes out as 1 instead of 82. dataBuf is an int16_t array. All the other math.h functions work fine with the conversion but the trig ones don't work....

Converting float to uint64 and uint32 behaves strangely

c++,floating-point,type-conversion
When I convert a 32bit float to a 64bit unsigned integer in C++, everything works as expected. Overflows cause the FE_OVERFLOW flag to be set (cfenv) and return the value 0. std::feclearexcept(FE_ALL_EXCEPT); float a = ...; uint64_t b = a; std::fexcept_t flags; std::fegetexceptflag(&flags, FE_ALL_EXCEPT); But when I convert a 32bit...

Conversion of double to int

java,type-conversion
I want to input the W into the int array. How can i do that? Sorry for the lousy question or english. public void setX (int Y , double W) { array[Y] = W; } ...

Swift convert decimal String to UInt8-Array

ios,swift,type-conversion
I have a very long String (600+ characters) holding a big decimal value (yes I know - sounds like a BigInteger) and need the byte representation of this value. Is there any easy way to archive this with swift? static func decimalStringToUInt8Array(decimalString:String) -> [UInt8] { ... } ...

Using [clock format] through TKinter changes how proc returns “”

python,tkinter,type-conversion,tcl
I am using TKinter to access an existing Tcl library from Python. One of the Tcl procs looks up values in a list and returns "" if the value is not found. The Python code sees the return value as unicode and checks to see if it is equal to...

GregorianCalendar outputs: The date is java.util.GregorianCalendar[time=1141556400000,areFieldsSet=true,areAllFieldsSet=true

java,type-conversion,gregorian-calendar
I have the following data in a text file which later I will Scanner in. 17-Mar-2006 1100 1280 16-Jan-2002 1120 1230 15-Jun-2003 1140 1900 I'm building this data as an "Stockmarket" object. The instance variable "date" is declared as GregorianCalendar. The constructor, String dt, should expect the form "dd-MMM-yyyy" in...

Reading a FAT16 file system

file,type-conversion,byte,fat16
I am trying to read a FAT16 file system to gain information about it like number of sectors, clusters, bytespersector etc... I am trying to read it like this: FILE *floppy; unsigned char bootDisk[512]; floppy = fopen(name, "r"); fread(bootDisk, 1, 512, floppy); int i; for (i = 0; i <...

Android: byte array to decimal string

java,android,type-conversion,bytearray
I have a byte array and I have to print it in a textview, in two differents format : hex string decimal string For hex string I use this function (found on stackoverflow) : final protected static char[] hexArray = "0123456789ABCDEF".toCharArray(); public static String bytesToHex(byte[] bytes) { char[] hexChars =...

What does it mean when you assign int to a variable in Python?

python,variables,int,type-conversion
i.e. x = int I understand that this will make x an integer if it is not already one, but I'd like to understand the process behind this. In particular, I'd like to know what int is (as opposed to int()). I know that int() is a function, but I'm...

no viable conversion from 'value_type' (aka 'char') to 'string' (aka 'basic_string, allocator >')

c++,string,type-conversion
string convert(string name) { string code = name[0]; ... } I get "no viable conversion from 'value_type' (aka 'char') to 'string' (aka 'basic_string, allocator >')" from this line. If I change it to: string convert(string name) { string code; code = name[0]; ... } Then it works. Can anyone explain...

415 Unsupported Media Type when I send json to spring controller

java,json,spring,jackson,type-conversion
I send POST http request with "Content-Type" "application/json" to my controller I have the following dependencies: <!--JSON--> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> </dependency> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-core-asl</artifactId> </dependency> the following controler method: @RequestMapping(value = "sendData.json", method = RequestMethod.POST,...

Converting bytes to a long: Why do some implementations bitwise-AND each byte with 0xff?

java,type-conversion,bit-manipulation,byte,long-integer
I'm looking at the implementation of java.io's DataInputStream.readLong() in SE6: private byte readBuffer[] = new byte[8]; public final long readLong() throws IOException { readFully(readBuffer, 0, 8); return (((long)readBuffer[0] << 56) + ((long)(readBuffer[1] & 255) << 48) + ((long)(readBuffer[2] & 255) << 40) + ((long)(readBuffer[3] & 255) << 32) + ((long)(readBuffer[4]...

VAADIN: Why I can't set a converter to a ComboBox?

combobox,type-conversion,converter,vaadin7
I've made a converter: public class BooleanToDateConverter implements Converter<Boolean, Date> { private static final long serialVersionUID = 1L; @Override public Date convertToModel(Boolean value, Class<? extends Date> targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { if (value == true) { return new Date(); } else { return null; } } @Override public Boolean...

How I can convert array to object in Javascript

javascript,arrays,types,type-conversion
I am trying to convert in Javascript an array A=['"age":"20"','"name":"John"','"email":"[email protected]"']; to object O={"age":"20","name":"John","email":"[email protected]"}. How I can do this. Thanks...

Typecasting int pointer to float pointer

c,pointers,floating-point,int,type-conversion
I'm trying to do the following int a[8]={1,2,3,4,5,6,7,8}; printf("%f\n", *(float *)a); printf("%f\n", *((float *)a+1)); printf("%f\n", *((float *)a+2)); printf("%f\n", *((float *)a+3)); printf("%f\n", *((float *)a+4)); printf("%f\n", *((float *)a+5)); printf("%f\n", *((float *)a+6)); printf("%f\n", *((float *)a+7)); I get 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 The reason why I'm trying to print the...

Convert char to float in c

c,floating-point,char,type-conversion
I need to convert char to float. I know we can do this with the help of atof() function. But I dont want to create another variable to hold the float. I want the converted float to go in the same variable. Like this operand = atof(operand) Here operand is...

Spring error converting nvarchar to bigint

java,spring,type-conversion,varchar,bigint
I'm getting an error whenever I try to save an object. The field causing the error is a string mapped to a varchar(200) in the database. The name of the field is localContact. Here's my code: Site.java: @Entity @Table(name = "SITE", uniqueConstraints = { @UniqueConstraint(columnNames = { "SITE_COUNTRY_ID", "SITE_NAME" })...

TypeError when split converting string to integer

python,string,split,integer,type-conversion
I get to read a line from a file that contain certain set of numbers per line. My problem is that the input is from a string line and then I need to process it as integer, making the conversion as usually suggested. Although I check previous post on this...

type conversion performance optimizable?

c#,xml,csv,optimization,type-conversion
The following snippet converts xml data to csv data in a data processing application. element is a XElement. I'm currently trying to optimize the performance of the application and was wondering if I could somehow combine the two operations going on below: Ultimately I still want access to the string...

reinterpret_cast from object to first member

c++,c++11,type-conversion,undefined-behavior,reinterpret-cast
I was looking at this answer and I was wondering if casting an object to its first member with reinterpret_cast and using the result could be safe in C++. Let's assume that we have a class A, a class B and an instance b of B: class A{ public: int...

Desconsider number after dot [duplicate]

java,android,type-conversion
This question already has an answer here: converting double to integer in java 2 answers I want to keep only the number before dot, what comes after I don't want to. For example: double x = 5.6 int y = 5 // the part before dot For this purpose...

Convert part of string to integer

string,python-2.7,unicode,integer,type-conversion
I have two time values of type unicode and str like below: time1 = "10:00 AM" #type: str time2 = "10:15 AM" #type: unicode I want to convert integer part of time1 and time2 i.e 10:00 and 10:15 to integer and check if time2 > time1. Is there any way...

std::vector to char* data loss

c++,vector,casting,type-conversion
I used cv::imencode to encode a cv::Mat as image/jpeg into a vector<uchar> now I want to convert that vector to type char *. vector<uchar> buf; // print buf to stdout to ensure that data is valid here for (auto c : buf) cout << c << endl; // cast vector...

Casting Classes and Setting Common Values

c#,class,type-conversion
We have a series of classes, which are derived from a common class: public class OurBaseClass { public string StatusMessage { get; set;} [other properties] } public class ProcessClass : OurBaseClass { public string SomeProcessInformation { get; set;} public string SomeMoreProcessInformation { get; set;} [other properties] } We are then...

Why does float argument fit to int function parameter?

c++,constructor,type-conversion
Please, look at this code: #include <iostream> class A { public: int my; A(int a=0) : my(a) { } }; int main() { A x = 7; // 1 A y = 6.7; // 2 std::cout << x.my << " " << y.my << "\n"; } It actually compiles although...