convert

Convert 4 bytes to an unsigned 32-bit integer and storing it in a long

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to read a binary file in Java. I need methods to read unsigned 8-bit values, unsigned 16-bit value and unsigned 32-bit values. What would be the best (fastest, nicest looking code) to do this? I've done this in c++ and did something like this: uint8_t *buffer; uint32_t value = buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] << 24; But in Java this causes a problem if for example buffer[1] contains a value which has it sign bit set as the result of a left-shift is an int (?). Instead of OR:ing in only 0xA5 at the specific

Convert string tuples to dict

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have malformed string: a = '(a,1.0),(b,6.0),(c,10.0)' I need dict : d = {'a':1.0, 'b':6.0, 'c':10.0} I try: print (ast.literal_eval(a)) #ValueError: malformed node or string: <_ast.Name object at 0x000000000F67E828> Then I try replace chars to 'string dict' , it is ugly and does not work: b = a.replace(',(','|{').replace(',',' : ') .replace('|',', ').replace('(','{').replace(')','}') print (b) {a : 1.0}, {b : 6.0}, {c : 10.0} print (ast.literal_eval(b)) #ValueError: malformed node or string: <_ast.Name object at 0x000000000C2EA588> What do

Convert Python List to Column in CSV

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a list of values (v1, v2, v3) and I want to write these to a column called VALUES in a csv. I'm using csvreader and csvwriter to get as far as I have. I've only figured out how to write them to rows using csvwriter.writerow. 回答1: It sounds like you have tried: values = [1, 2, 3, 4, 5] thecsv = csv.writer(open("your.csv", 'wb')) thecsv.writerow(values) Perhaps you should try: values = [1, 2, 3, 4, 5] thecsv = csv.writer(open("your.csv", 'wb')) for value in values: thecsv.writerow(value) 文章来源: Convert Python List to Column in CSV

How to convert from boost::multiprecision::cpp_int to cpp_dec_float&lt;0&gt; (rather than to cpp_dec_float_50, etc.)?

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: As is made clear in the Boost Multiprecision library documentation, it is straightforward to convert from a boost::multiprecision::cpp_int to a boost::multiprecision::cpp_dec_float : // Some interconversions between number types are completely generic, // and are always available, albeit the conversions are always explicit: cpp_int cppi(2); cpp_dec_float_50 df(cppi); // OK, int to float // <-- But fails with cpp_dec_float<0>! The ability to convert from a cpp_int to a fixed-width floating-point type (i.e., a cpp_dec_float_50 ) gives one hope

How to convert BigDecimal to Double in spring-data-mongodb framework

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Spring Data MongoDB mapping by default converts BigDecimal to String. However, I want them to be converted as Double in mongodb. This is required for latter to make queries on this field in mongodb (comparison queries/aggregation queries). How can I reigster my own converter (BigDecimalToDouble / DoubleToBigDecimal) to do this? 回答1: Here's how you can add your own converters: <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg ref="mongoDbFactory"/> <constructor-arg ref="mappingConverter"/>

Convert Invalid Json into valid json android?

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I want to convert jnvalid JSON data into valid JSON data. I have JSON like this below. Is there any logic to change it using Java? { name : date , order : 1 , required : true , type : date , placeholder : Expense Date } I want valid JSON data formatted as below: { "name" : "date" , "order" : "1" , "required" : "true" , "type" : "date" , "placeholder" : "Expense Date" } 回答1: I'm not going to do it for you as you haven't provided any code to what you have done but I will guide you on how to do it. Iterate over the file or the string

How to convert moment date to a string and remove the moment object

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a React Web App and a React Native Mobile App. When I pass a moment date object from my react web app to my backend, it gets converted to a string somehow and it works with my backend. When I do it with my react native mobile app, it passes the date as a moment object and it doesn't get converted to a string and it doesn't work. Is there a way to convert the moment object into a plain string like "Tue May 05 2015 23:59:59 GMT+0800 (HKT)" I tried toString() and toUTCString() and it doesn't work. Thanks. 回答1: Use moment().format() to

how to convert an int to a char C++

匿名 (未验证) 提交于 2019-12-03 08:52:47
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Im having trouble with an assignment where I have to convert three variables of a clock (int hour, int minutes, and bool afternoon) to be converted to a string in a method. I tried converting the int to a char and then replacing each string with the char. The function is suppose to return T/F if the conversion worked or not. Here is what I have so far: class Time { private : int hour ; int minutes ; bool afternoon ; public : void setHour ( int hr ); void setMinutes ( int min ); void setAfternoon ( bool aft ); int getHour (); int

Convert between string, u16string &amp; u32string

匿名 (未验证) 提交于 2019-12-03 08:52:47
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've been looking for a way to convert between the Unicode string types and came across this method . Not only do I not completely understand the method (there are no comments) but also the article implies that in future there will be better methods. If this is the best method, could you please point out what makes it work, and if not I would like to hear suggestions for better methods. 回答1: mbstowcs() and wcstombs() don't necessarily convert to UTF-16 or UTF-32, they convert to wchar_t and whatever the locale wchar_t encoding is. All

How to convert HSSFWorkbook to XSSFWorkbook using Apache POI?

匿名 (未验证) 提交于 2019-12-03 08:52:47
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: How to convert org . apache . poi . hssf . usermodel . HSSFWorkbook to org . apache . poi . xssf . usermodel . XSSFWorkbook in Apache POI? Environment : JSE1.6 JBossAS 4.3.2 POI 3.7 回答1: this code has been adapted from what I found here on coderanch forum public final class ExcelDocumentConverter { public static XSSFWorkbook convertWorkbookHSSFToXSSF ( HSSFWorkbook source ) { XSSFWorkbook retVal = new XSSFWorkbook (); for ( int i = 0 ; i styleMap = ( copyStyle ) ? new HashMap () : null ; for ( int i = source . getFirstRowNum (); i