data-conversion

How do I print bytes as hexadecimal?

一笑奈何 提交于 2019-11-27 11:44:23
问题 I know in C# you can use String.Format method. But how do you do this in C++? Is there a function that allows me to convert a byte to a Hex?? Just need to convert a 8 byte long data to Hex, how do I do that? 回答1: Well you can convert one byte (unsigned char) at a time into a array like so char buffer [17]; buffer[16] = 0; for(j = 0; j < 8; j++) sprintf(&buffer[2*j], "%02X", data[j]); 回答2: If you want to use C++ streams rather than C functions, you can do the following: int ar[] = { 20, 30, 40

iOS convert large numbers to smaller format

青春壹個敷衍的年華 提交于 2019-11-27 10:39:29
How can I convert all numbers that are more than 3 digits down to a 4 digit or less number? This is exactly what I mean: 10345 = 10.3k 10012 = 10k 123546 = 123.5k 4384324 = 4.3m Rounding is not entirely important, but an added plus. I have looked into NSNumberFormatter but have not found the proper solution, and I have yet to find a proper solution here on SO. Any help is greatly appreciated, thanks! Luca Iaco -(NSString*) suffixNumber:(NSNumber*)number { if (!number) return @""; long long num = [number longLongValue]; int s = ( (num < 0) ? -1 : (num > 0) ? 1 : 0 ); NSString* sign = (s == -1 ?

Why does Ruby's String#to_i sometimes return 0 when the string contains a number?

本小妞迷上赌 提交于 2019-11-27 07:36:06
问题 I was just trying out Ruby and I came across String#to_i . Suppose I have this code: var1 = '6 sldasdhkjas' var2 = 'aljdfldjlfjldsfjl 6' Why does puts var1.to_i output 6 when puts var2.to_i gives 0 ? 回答1: The to_i method returns the number that is formed by all parseable digits at the start of a string. Your first string starts with a with digit so to_i returns that, the second string doesn't start with a digit so 0 is returned. BTW, whitespace is ignored, so " 123abc".to_i returns 123. 回答2:

Matching records based on Person Name

核能气质少年 提交于 2019-11-27 05:22:54
问题 Are there any tools or methods that can be used for matching by a person's name between two different data sources? The systems have no other common information and the names have been entered differently in many cases. Examples of non-exact matches: King Jr., Martin Luther = King, Martin (exclude suffix) Erving, Dr. J. = Erving, J. (exclude prefix) Obama, Barak Hussein = Obama, Barak (exclude middle name) Pufnstuf, H.R. = Pufnstuf, Haibane Renmei (match abbreviations) Tankengine, Thomas =

How do I convert a Char to Int?

我们两清 提交于 2019-11-26 23:14:15
问题 So I have a String of integers that looks like "82389235" , but I wanted to iterate through it to add each number individually to a MutableList . However, when I go about it the way I think it would be handled: var text = "82389235" for (num in text) numbers.add(num.toInt()) This adds numbers completely unrelated to the string to the list. Yet, if I use println to output it to the console it iterates through the string perfectly fine. How do I properly convert a Char to an Int ? 回答1: That's

Why am I getting a “[SQL0802] Data conversion of data mapping error” exception?

只愿长相守 提交于 2019-11-26 22:02:25
问题 I am not very familiar with iseries/DB2. However, I work on a website that uses it as its primary database. A new column was recently added to an existing table. When I view it via AS400, I see the following data type: Type: S Length: 9 Dec: 2 This tells me it's a numeric field with 6 digits before the decimal point, and 2 digits after the decimal point. When I query the data with a simple SELECT ( SELECT MYCOL FROM MYTABLE ), I get back all the records without a problem. However, when I try

Convert String with Dot or Comma as decimal separator to number in JavaScript

那年仲夏 提交于 2019-11-26 20:51:55
问题 An input element contains numbers a where comma or dot is used as decimal separator and space may be used to group thousands like this: '1,2' '110 000,23' '100 1.23' How would one convert them to a float number in the browser using JavaScript? jQuery and jQuery UI are used. Number(string) returns NaN and parseFloat() stops on first space or comma. 回答1: Do a replace first: parseFloat(str.replace(',','.').replace(' ','')) 回答2: The perfect solution accounting.js is a tiny JavaScript library for

Convert Latitude and Longitude to point in 3D space

我的梦境 提交于 2019-11-26 19:25:11
问题 I need to convert latitude and longitude values to a point in the 3-dimensional space. I've been trying this for about 2 hours now, but I do not get the correct results. The Equirectangular coordinates come from openflights.org. I've tried several combinations of cos and sin , but the result did never look like our little beloved earth. In the following, you can see the result of applying the conversion Wikipedia suggests. I think one can guess from context what c4d.Vector is. def llarToWorld

Convert nested JSON array into separate columns in CSV file

青春壹個敷衍的年華 提交于 2019-11-26 16:44:15
I have a JSON file that looks like this: { "id": 10011, "title": "Test procedure", "slug": "slug", "url": "http://test.test", "email": "test@test.com", "link": "http://test.er", "subject": "testing", "level": 1, "disciplines": [ "discipline_a", "discipline_b", "discipline_c" ], "areas": [ "area_a", "area_b" ] }, I was trying to use the following command to convert that into the CSV file: (Get-Content "PATH_TO\test.json" -Raw | ConvertFrom-Json)| Convertto-CSV -NoTypeInformation | Set-Content "PATH_TO\test.csv" However, for disciplines and areas I am getting System.Object[] in the resulting CSV

Java lib or app to convert CSV to XML file? [closed]

帅比萌擦擦* 提交于 2019-11-26 16:01:15
Is there an existing application or library in Java which will allow me to convert a CSV data file to XML file? The XML tags would be provided through possibly the first row containing column headings. svrist Maybe this might help: JSefa You can read CSV file with this tool and serialize it to XML. Laurent K As the others above, I don't know any one-step way to do that, but if you are ready to use very simple external libraries, I would suggest: OpenCsv for parsing CSV (small, simple, reliable and easy to use) Xstream to parse/serialize XML (very very easy to use, and creating fully human