converter

Convert an integer to binary without using the built-in bin function

試著忘記壹切 提交于 2019-11-27 04:49:28
问题 This function receives as a parameter an integer and should return a list representing the same value expressed in binary as a list of bits, where the first element in the list is the most significant (leftmost) bit. My function currently outputs '1011' for the number 11, I need [1,0,1,1] instead. For example, >>> convert_to_binary(11) [1,0,1,1] 回答1: def trans(x): if x == 0: return [0] bit = [] while x: bit.append(x % 2) x >>= 1 return bit[::-1] 回答2: Just for fun - the solution as a recursive

JSF 2 - f:selectItems with a Date keyed Map

て烟熏妆下的殇ゞ 提交于 2019-11-27 04:48:10
问题 The below selectItems is fed from a Session Scoped Map. When the user clicks the Submit button, it is supposed to set a date field in the Request Scoped backing bean and display it on the page. <h:selectOneMenu value="#{dropDown.selectedDate}"> <f:selectItems value="#{mapValues.dateMap.entrySet()}" var="entry" itemLabel="#{entry.value}" itemValue="#{entry.key}" /> </h:selectOneMenu> <h:commandButton value="Submit" /> You selected Date #{dropDown.selectedDate} However, the following conversion

JavaScript: Need functions to convert a string containing binary to hex, then convert back to binary

半腔热情 提交于 2019-11-27 04:34:33
Lets say I have a string in JavaScript with binary data in it. It may look like this: var binary = '00001000010001000101010100001110'; I need some reliable functions to convert this into a hexadecimal string, and then convert back from that hexadecimal to a binary string again. I know about the following functions // Convert binary to hexadecimal var hex = parseInt(binaryCharacters, 2).toString(16); // Convert hexadecimal to binary var binary = parseInt(hex, 16).toString(2) But I'm not sure how to convert the whole string at once. Am I right in understanding I need to convert each 4 binary

Free (preferably) PHP RTF to HTML converter? [closed]

旧时模样 提交于 2019-11-27 03:39:03
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I am writing a converter for an old db app which contains a large amount of user entered RTF text. Ideally, the RAW RTF should be converted to HTML for display in a browser. I have tried rtfparseclass from PHP Classes, which works ok, but seems to be thrown off but some of the embedded font definitions. For

Converting JSON to XML

痞子三分冷 提交于 2019-11-27 03:15:17
问题 I trying to convert JSON output into XML. Unfortunately I get this error: JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName. This is what I up to now created. string url = string.Format("https://graph.facebook.com/{0}?fields=posts.fields(message)&access_token={1}", user_name, access_token); HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; using

Need API for currency converting [closed]

偶尔善良 提交于 2019-11-27 03:04:28
Please advice API for currency converting which returns JSON or small size html. I use http://www.google.com/finance/converter?a=1&from=RUB&to=USD that returns HTML of 11 kb. I use it in my iOS app. Thanks in advance! free.currencyconverterapi.com returns results in JSON format. The web service also supports JSONP. The API is very easy to use, and it lets you convert one currency to another. Disclaimer, I'm the author of the website. A sample conversion URL is: http://free.currencyconverterapi.com/api/v6/convert?q=USD_PHP&compact=ultra&apiKey=sample-api-key which will return a value in json

How to boolean && two visibility converters

若如初见. 提交于 2019-11-27 03:04:13
问题 I have two separate converters for visibility, one based on whether a field has been updated and one based on whether a field is allowed to be seen. I use the updatedField one for each text item on my page so that a star shows up next to an updated field. But some text items only are visible to some users based on permission levels. For example: <Image Visibility="{Binding ElementName=MyObject, Path=UpdatedFields, Mode=OneWay, Converter={StaticResource updatedFieldConverter},

Register converters and converterFactories with annotations in Spring 3

纵然是瞬间 提交于 2019-11-27 02:51:26
问题 First of all ... Im relatively new in Spring, I use spring 3.x and I DONT LIKE SPRING'S XML CONFIGURATION FILES ... I dont want for every refactoring I do, to run into XML file for updates ... I'm trying to configure spring in a way that for any request, if I have some @RequestParam/@RequestBody/@PathVariable etc with type other than String in my hadlers, spring will convert values to that type correctly or put null to handler's args (I never use primitive types in handler arguments). So far

use of boolean to color converter in XAML

家住魔仙堡 提交于 2019-11-27 02:38:38
问题 I am working on WPF application.I have bound my textblock to my button. I want to set foreground of my textblock to black color when its associated button's isEnabled is true. I want to do this using converter. But its not working . also not giving any error. I have declared following class in my "Models" folder. public class BrushColorConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if ((bool)value) { { return System

How to write a custom converter for <p:pickList>

那年仲夏 提交于 2019-11-27 00:28:34
How can I write a custom converter when working with PrimeFaces components that use a list of POJO? My particular problem is with <p:pickList> <p:pickList converter="????" value="#{bean.projects}" var="project" itemLabel="#{project.name}" itemValue="#{project}"> Without a converter I get java.lang.ClassCastException because JSF sets the submitted values with unconverted java.lang.String submitted values. It's possible, whithout other database access, but i don't know the best way. I use a very specific converter, works only for picklist. Try this: @FacesConverter(value =