casting Questions

31

Solved

PHP has an intval() function that will convert a string to an integer. However I want to check that the string is an integer beforehand, so that I can give a helpful error message to the user if it...
Trimerous asked 6/1, 2010 at 10:21

4

Solved

I've stored a pointer to a type_info object. int MyVariable = 123; const std::type_info* Datatype = &typeid(MyVariable); How might I use this to typecast another variable to that type? I tri...
Plantain asked 11/2, 2011 at 18:43

7

Solved

Studying for my OCA Java SE 7 Programmer I exam, so newbie question. I have an example question I do not understand. The following code compiles, but gives a ClassCastException at runtime: interfa...
Bronwyn asked 10/11, 2013 at 21:17

4

Solved

Is there any benefit of casting NULL to a struct pointer in C ? For example: typedef struct List { .... } List; List *listPtr = ((List *) NULL) ; Example from PostgreSQL source: #define NIL ...
Swayne asked 23/8, 2012 at 14:39

8

Solved

This code: SELECT JSON_EXTRACT('{"hello": null}', '$.hello') Returns null. However, this is not the MySQL native NULL. For example, this: SELECT COALESCE(JSON_EXTRACT('{"hello": null}', '$.hel...
Euterpe asked 13/6, 2016 at 17:21

5

Solved

I am unable to understand the following: In java, long l = 130L; byte b = (byte)l; If I print the value of b, why do I get -126? What is the bit representation of long l?
Reticulate asked 11/4, 2011 at 16:0

4

Solved

i have some low level image/texture operations where 32-bit colors are stored as UInt32 or int and i need a really fast bitwise conversion between the two. e.g. int color = -2451337; //except...
Populate asked 30/8, 2010 at 13:41

12

Solved

What are the proper uses of: static_cast dynamic_cast const_cast reinterpret_cast (type)value (C-style cast) type(value) (function-style cast) How does one decide which to use in which specific c...
Zeppelin asked 1/12, 2008 at 20:11

5

Solved

Recently, I was trying to store and read information from files in Python, and came across a slight problem: I wanted to read type information from text files. Type casting from string to int or to...
Johnettajohnette asked 2/8, 2012 at 10:17

3

Solved

I need to convert string to variable value. I found solution only for C#. I need it in Java. public class Property<T> { T value; public void setValue(String input){ if(value instanceof ...
Walter asked 5/7, 2014 at 18:43

3

Solved

uint32_t a = 10; uint16_t b = 0; if (a > b) { printf("a > b\n"); } I was expecting that b would get promoted to int and the compiler would complain about comparing signed and uns...
Pumping asked 13/3, 2023 at 16:6

9

Solved

How do I avoid implicit casting on non-constructing functions? I have a function that takes an integer as a parameter, but that function will also take characters, bools, and longs. I believe it do...
Limes asked 13/10, 2012 at 22:19

2

Solved

I’ve seen low-level bitwise expressions that use ~0 to generate a bit-pattern of all 1s, which is then used as masks, etc. For example on K&R page 45: /* getbits: get n bits from position p */ ...
Insincere asked 10/3, 2023 at 5:23

9

I want to convert string to integer in golang. But I don't know the format of string. For example, "10" -> 10, "65.0" -> 65, "xx" -> 0, "11xx" -> 11, "xx11"->0 I do some searching and find strconv...
Judie asked 18/7, 2015 at 4:8

5

Solved

I'm trying to convert a Vec of u32s to a Vec of u8s, preferably in-place and without too much overhead. My current solution relies on unsafe code to re-construct the Vec. Is there a better way to ...
Locomotor asked 6/4, 2018 at 10:13

5

Solved

It seems there is no way of such one-line conversion using std. I do not like this kind of verbosity: match my_bool { true => Ok(()), false => Err(MyError::False), } I would like to use a ...
Opsis asked 23/2, 2019 at 12:0

11

Solved

How can I cast a value from Enum1 to Enum 2 in Java? Here is an example of what I'm trying to do : public enum Enum1 { ONE, TWO, THREE; } public enum Enum2 { FOUR, FIVE, SIX; } So I want ...
Exodus asked 2/9, 2011 at 13:54

22

Solved

How can I cast an Object to an int in java?
Shelashelagh asked 7/9, 2010 at 18:15

8

Solved

I have in model: protected $casts = [ 'date' => 'date', ]; Does laravel have some ability to set cast format, something like: protected $casts = [ 'date' => 'date_format:d/m/yyyy', ]; ...
Polyhydroxy asked 16/6, 2016 at 11:11

7

Solved

I am new to Scala and I am finding the need to convert a Boolean value to an Integer. I know I can use something like if (x) 1 else 0 but I would like to know if there is a preferred method, or som...
Kliber asked 13/4, 2010 at 22:47

4

I have two types, T and U, and I want to know whether an implicit cast operator is defined from T to U. I'm aware of the existence of IsAssignableFrom, and this is not what I'm looking for, as it ...
Boozy asked 15/8, 2015 at 13:28

13

Solved

What is the best way to convert a double to an int? Should a cast be used?
Disturbance asked 15/11, 2010 at 6:27

6

Solved

FYI: Swift bug raised here: https://bugs.swift.org/browse/SR-3871 I'm having an odd problem where a cast isn't working, but the console shows it as the correct type. I have a public protocol p...
Incentive asked 3/2, 2017 at 22:3

3

Solved

before judging that this question is already answered, please read the description. I have this simple code below: Dictionary<string, object> d = new Dictionary<string, object>(); d.Ad...
Crosscrosslet asked 19/7, 2019 at 7:41

1

Solved

I have an enum in my model class: MyRepresentation { list, tabs, single } I have already added an adapter and registered it. I have given it a proper type id and fields. It gives error: HiveError...
Bachelor asked 9/1, 2023 at 13:48

© 2022 - 2024 — McMap. All rights reserved.