Negative numbers to binary string in JavaScript

Short answer: The toString() function takes the decimal, converts it to binary and adds a “-” sign. A zero fill right shift converts it’s operands to signed 32-bit integers in two complements format. A more detailed answer: Question 1: //If you try (-3).toString(2); //show “-11” It’s in the function .toString(). When you output a number … Read more

Join an array by a comma and a space

In JavaScript there’s a .join() method on arrays to get a string, which you can provide the delimiter to. In your case it’d look like this: var myArray = [‘css’,’html’,’xhtml’,’html5′,’css3′,’javascript’,’jquery’,’lesscss’,’arrays’,’wordpress’,’facebook’,’fbml’,’table’,’.htaccess’,’php’,’c’,’.net’,’c#’,’java’]; var myString = myArray.join(‘, ‘); You can test it out here

C# debugging: [DebuggerDisplay] or ToString()?

Using [DebuggerDisplay] is meant only for the debugger. Overriding ToString() has the “side effect” of changing the display at runtime. This may or may not be a good thing. Often, you want more info during debugging than your standard ToString() output, in which case you’d use both. For example, in your case, the “ToString” implementation … Read more

Map to String in Java

Use Object#toString(). String string = map.toString(); That’s after all also what System.out.println(object) does under the hoods. The format for maps is described in AbstractMap#toString(). Returns a string representation of this map. The string representation consists of a list of key-value mappings in the order returned by the map’s entrySet view’s iterator, enclosed in braces (“{}”). … Read more

Convert a vector to a string

Definitely not as elegant as Python, but nothing quite is as elegant as Python in C++. You could use a stringstream … #include <sstream> //… std::stringstream ss; for(size_t i = 0; i < v.size(); ++i) { if(i != 0) ss << “,”; ss << v[i]; } std::string s = ss.str(); You could also make use … Read more

What is this: [Ljava.lang.Object;?

[Ljava.lang.Object; is the name for Object[].class, the java.lang.Class representing the class of array of Object. The naming scheme is documented in Class.getName(): If this class object represents a reference type that is not an array type then the binary name of the class is returned, as specified by the Java Language Specification (ยง13.1). If this … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)