data-conversion

Convert vector<unsigned char> {1,2,3} into string “1-2-3” AS DIGITS

北城以北 提交于 2019-11-29 17:02:53
I want to display numbers in a std::vector<unsigned char> on a screen, but on its way to the recipient, I need to stuff these numbers into a std::string . Whatever I tried ( atoi , reinterpret_cast , string.c_str() ...), gave me either a nonsense, or a letter representation of those original numbers - i.e. their corresponding ascii characters. So how do I easily (preferably standard method) convert vector<unsigned char> {1,2,3} into a string "1-2-3" ? In the Original Post (later edited) I mentioned, that I could do that in C# or Java. Upon the request of πάντα ῥεῖ to provide example in C# or

SSIS how to convert string (DT_STR) to money (DT_CY) when source has more than 2 decimals

孤人 提交于 2019-11-29 16:05:26
I have a source flat file with values such as 24.209991, but they need to load to SQL Server as type money. In the DTS (which I am converting from), that value comes across as 24.21. How do I convert that field in SSIS? Right now, I am just changing the type from DT_STR to DT_CY, and it gives a run error of 'Data conversion failed. The data conversion for column "Col003" returned status value 2 and status text "The value could not be converted because of a potential loss of data.".' Do I use a Data Conversion task? And then what? I've also tried setting the source output column to DT_NUMERIC,

Map<String, HashSet<String>> to JSON, & Pretty Print

风格不统一 提交于 2019-11-29 15:53:05
I'm trying to make my dataset correspond to this example: var family = [{ "name" : "Jason", "age" : "24", "gender" : "male" }, { "name" : "Kyle", "age" : "21", "gender" : "male" }]; I have a Map<String, HashSet<String>> of Names and unique alpha-numeric values correponding to specific entities to which those names could refer, let's call these entry items "IDs". So for instance, Fyodor Mikhailovich Dostoyevsky would perhaps be related to the ID Q626 , because that's a very specific reference, there aren't many widely known figures with that name. Whereas, Bush might be attached to G027 , Q290

Convert String to/from byte array without encoding

喜你入骨 提交于 2019-11-29 15:00:24
I have a byte array read over a network connection that I need to transform into a String without any encoding, that is, simply by treating each byte as the low end of a character and leaving the high end zero. I also need to do the converse where I know that the high end of the character will always be zero. Searching the web yields several similar questions that have all got responses indicating that the original data source must be changed. This is not an option so please don't suggest it. This is trivial in C but Java appears to require me to write a conversion routine of my own that is

Byte array to Hex string conversion in javascript

梦想的初衷 提交于 2019-11-29 11:59:41
问题 I have a byte array of the form [4,-101,122,-41,-30,23,-28,3,..] which I want to convert in the form 6d69f597b217fa333246c2c8 I'm using below function function toHexString(bytes) { return bytes.map(function(byte) { return (byte & 0xFF).toString(16) }).join('') } which is giving me a string of the same form but I suspect that it's not an efficient conversion because the hex string is bit shorter than expected. I think translating should get "0a10a6dc". Please tell me if I'm wrong or is this a

How can I convert an Integer (e.g 19000101 ) to java.util.Date? [closed]

不打扰是莪最后的温柔 提交于 2019-11-29 10:20:09
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . Here's my code: Integer value = 19000101 ; How can I convert the above Integer represented in YYYYMMDD format to YYYY-MM-DD format in java.util.Date ? 回答1: First you have to parse your format into date object using formatter specified Integer value = 19000101; SimpleDateFormat originalFormat = new

Convert char* to uint8_t

好久不见. 提交于 2019-11-29 07:15:44
I transfer message trough a CAN protocol . To do so, the CAN message needs data of uint8_t type . So I need to convert my char* to uint8_t. With my research on this site, I produce this code : char* bufferSlidePressure = ui->canDataModifiableTableWidget->item(6,3)->text().toUtf8().data();//My char* /* Conversion */ uint8_t slidePressure [8]; sscanf(bufferSlidePressure,"%c", &slidePressure[0]); As you may see, my char* must fit in sliderPressure[0] . My problem is that even if I have no error during compilation, the data in slidePressure are totally incorrect . Indeed, I test it with a char* =

Get date representation in seconds?

这一生的挚爱 提交于 2019-11-29 03:41:20
I am using an API which requires a date parameter as a number of seconds, an int . My problem is that I currently store this time in java.util.date and I was wondering if there is some way to convert the java.util.date variable to seconds so that I can fit it into the int parameter which the API requires? import java.util.Date; ... long secs = (new Date().getTime())/1000; ... Please see - http://docs.oracle.com/javase/6/docs/api/java/util/Date.html#getTime() java.util.Date.getTime() it returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object. java

Convert string with comma to integer

笑着哭i 提交于 2019-11-28 21:44:07
问题 Is there any neat method to convert "1,112" to integer 1112, instead of 1? I've got one, but not neat: "1,112".split(',').join.to_i #=> 1112 回答1: How about this? "1,112".delete(',').to_i 回答2: You may also want to make sure that your code localizes correctly, or make sure the users are used to the "international" notation. For example, "1,112" actually means different numbers across different countries. In Germany it means the number a little over one, instead of one thousand and something.

Why does ~True result in -2?

一世执手 提交于 2019-11-28 16:53:47
问题 In Python console: ~True Gives me: -2 Why? Can someone explain this particular case to me in binary? 回答1: int(True) is 1 . 1 is: 00000001 and ~1 is: 11111110 Which is -2 in Two's complement 1 1 Flip all the bits, add 1 to the resulting number and interpret the result as a binary representation of the magnitude and add a negative sign (since the number begins with 1): 11111110 → 00000001 → 00000010 ↑ ↑ Flip Add 1 Which is 2, but the sign is negative since the MSB is 1. Worth mentioning: Think