type-conversion

Convert to a datatype given in string format

人走茶凉 提交于 2021-02-19 04:55:26
问题 I have been searching for a solution for quite a while now and couldn't find anything close. What I want to achieve: I have two strings, 'a' and 'b'. String 'a' contains a datatype, for example "Boolean". String b contains a value like "1" or "False", could be anything. I want to be able to store the value of string 'b' in a variable which has the datatype of string 'a'. If I would itterate trough a list of results with the same values as given in the example the results would be as following

Passing integer to php $_GET via url

眉间皱痕 提交于 2021-02-19 03:45:28
问题 So I'm doing some CTF and one of the challenge is about php type juggling. The code looks something like this if($_GET['var1'] == hash('md4', $_GET['var1'])) { //print flag } So I was 80% sure that I need to pass in an integer so it'll be true but all I can manipulate is the url. I tried using python request to do it but still failed. import requests url = 'http://example.com' params = dict(var1=0) r = requests.get(url=url, params=params) Is there any special case where php will treat the

2 Chars to Short in C

扶醉桌前 提交于 2021-02-19 00:21:18
问题 I've got 2 chars. Char 128 and Char 2 . How do I turn these chars into the Short 640 in C? I've tried unsigned short getShort(unsigned char* array, int offset) { short returnVal; char* a = slice(array, offset, offset+2); memcpy(&returnVal, a, 2); free(a); return returnVal; } But that didn't work, it just displays it as 128 . What's the preferred method? 回答1: I found that the accepted answer was nearly correct, except i'd run into a bug where sometimes the top byte of the result would be 0xff

Deleting all lvalue conversion operators

馋奶兔 提交于 2021-02-18 12:55:08
问题 I want to avoid all lvalue conversions from a type to another type: struct A {}; struct T { A a; operator A() { return a; } //operator A&() = delete; how to delete lvalue conversions to A? }; void bar(A) {} void foo(const A&) {} void foo2(A&) {} int main() { T t; bar(t); // fine foo(t); // should never convert to ref-to-const A foo2(t); // should never convert to ref-to A return 0; } Is this possible? How and which conversion operators do I need to delete? Example on godbolt 回答1: You might do

Opencv Python open dng format

梦想的初衷 提交于 2021-02-18 12:31:02
问题 I can't figure out how to open a dng file in opencv. The file was created when using the pro options of the Samsung Galaxy S7. The images that are created when using those options are a dng file as well as a jpg of size 3024 x 4032 (I believe that is the dimensions of the dng file as well). I tried using the answer from here (except with 3 colors instead of grayscale) like so: import numpy as np fd = open("image.dng", 'rb') rows = 4032 cols = 3024 colors = 3 f = np.fromfile(fd, dtype=np.uint8

Forbid integer conversion with precision loss

荒凉一梦 提交于 2021-02-18 06:13:21
问题 How to prevent such code from compiling? #include <vector> #include <limits> #include <iostream> #include <cstdint> int main() { std::vector<int16_t> v; v.emplace_back(std::numeric_limits<uint64_t>::max()); std::cout << v.back() << std::endl; return 0; } g++ and clang with -std=c++14 -Wall -Wextra -Werror -pedantic -Wold-style-cast -Wconversion -Wsign-conversion don't even warn about it. The example also compiles without warnings with std::vector<uint16_t> 回答1: Add -Wsystem-headers to the

How to convert Console.ReadLine() to double in simple calculator ? C# Problem with exception

浪子不回头ぞ 提交于 2021-02-17 05:20:30
问题 I used double.Parse and Convert.ToDouble and got the same error System.FormatException: Input string was not in a correct format. When I write in console 10.2 or any other double number. I learnt from a tutorial and I followed it step by step but I have no idea how to solve this. Also I am using Visual Studio. Console.WriteLine("Enter a number: "); double num1 = double.Parse(Console.ReadLine()); Console.Write("Enter operator: "); string op = Console.ReadLine(); Console.WriteLine("Enter a

How to convert Console.ReadLine() to double in simple calculator ? C# Problem with exception

孤者浪人 提交于 2021-02-17 05:20:08
问题 I used double.Parse and Convert.ToDouble and got the same error System.FormatException: Input string was not in a correct format. When I write in console 10.2 or any other double number. I learnt from a tutorial and I followed it step by step but I have no idea how to solve this. Also I am using Visual Studio. Console.WriteLine("Enter a number: "); double num1 = double.Parse(Console.ReadLine()); Console.Write("Enter operator: "); string op = Console.ReadLine(); Console.WriteLine("Enter a

MySQL code to convert Excel datetime

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-16 20:15:47
问题 Excel's datetime values look like 42291.60493, which means MySQL sees them as strings and not as dates. Is there a MySQL code that can convert them to MySQL datetime? (i.e. like in MS SQL) 回答1: I can think of 2 solutions: Convert your dates within excel to a formatted date string that conforms to mysql's date and time format using text() function within excel. Convert the number using calculation to date within mysql: (the expression below may be simplified) select date_add(date_add(date(

How to convert varchar to decimal(38,2)?

梦想的初衷 提交于 2021-02-11 17:15:32
问题 I have a problem converting from a varchar '000000113754' to decimal 1137.54 I'm comparing two expressions: 1. select STUFF('000000113754', LEN('000000113754') - 1, 0, '.') 2. select STUFF([dbo].fn_PrepareNumeric(('000000113754' + '-'), '+','-'), LEN('000000113754') - 1, 0, '.') The function fn_PrepareNumeric just checks for the sign and appends '-' in front if the sign is - . That's all. The problem is that the first expression gives me the correct varchar - 0000001137.54 , and the second