How do you express an integer as a binary number with Python literals?
I was easily able to find the answer for hex:
>>> 0x12AF
4783
>>> 0x100
256
and, octal:
>>> 01267
695
>>> 0100
64
How do you use literals to express binary in Python?
Summary of Answers
Python 2.5 and earlier: can express bi...
#include <stdio.h>int main() { unsigned long long int num = 285212672; //FYI: fits in 29 bits int normalInt = 5; printf("My number is %d bytes wide and its value is %ul. A normal number is %d.\n", sizeof(num), num, normalInt); return 0;}
Output:
My number is 8 bytes wide and its value is 285212672l. A normal number is 0.
I...
What is the difference, if any, between these methods of indexing into a PHP array:
$array[$index]
$array["$index"]
$array["{$index}"]
I'm interested in both the performance and functional differences.
Update:
(In response to @Jeremy) I'm not sure that's right. I ran this code:
$array = array(100, 200, 300);
print_r($array);
...
Perl has OOP features, but they are somewhat rarely used. How do you create and use Perl objects with methods and properties?
...
How do you create a static class in C++? I should be able to do something like:
cout << "bit 5 is " << BitParser::getBitAt(buffer, 5) << endl;
Assuming I created the BitParser class. What would the BitParser class definition look like?
...
I want to create a function that performs a function passed by parameter on a set of data. How do you pass a function as a parameter in C?
...
In Ruby, what's the difference between {} and []?
{} seems to be used for both code blocks and hashes.
are [] only for arrays?
The documention isn't very clear.
...
I know that |DataDirectory| will resolve to App_Data in an ASP.NET application but is that hard-coded or is there a generalized mechanism at work along the lines of %environment variables%?
...
I have defined a Java function:
static <T> List<T> createEmptyList() {
return new ArrayList<T>();
}
One way to call it is like so:
List<Integer> myList = createEmptyList(); // Compiles
Why can't I call it by explicitly passing the generic type argument? :
Object myObject = createEmtpyList<Integer>(); // Doesn't compile. Why?
...
Ever since I first made the mistake of doing an assignment in an if I've always written my ifs like this:
if (CONST == variable) {
to avoid the common (at least for me) mistake of doing this:
if (variable = CONST) { //WRONG, assigning 0 to variable
And since I read Joel Spolsky's essay Making Wrong Code Look Wrong I've been trying ...
In C#, what is the difference (if any) between these two lines of code?
tmrMain.Elapsed += new ElapsedEventHandler(tmrMain_Tick);
and
tmrMain.Elapsed += tmrMain_Tick;
Both appear to work exactly the same. Does C# just assume you mean the former when you type the latter?
...
Can I get a 'when to use' for these and others?
<% %>
<%# EVAL() %>
Thanks
...
There are two weird operators in C#:
the true operator
the false operator
If I understand this right these operators can be used in types which I want to use instead of a boolean expression and where I don't want to provide an implicit conversion to bool.
Let's say I have a following class:
public class MyType
{
pub...
In the following method, what does the * and ** do for param2? I'm new to Python...I assume it's a reference or pointer. Answers?
def foo(param1, *param2):
def bar(param1, **param2):
...
I have two Python dictionaries, and I want to write a single expression that returns these two dictionaries, merged. The update() method would be what I need, if it returned its result instead of modifying a dict in-place.
>>> x = {'a':1, 'b': 2}
>>> y = {'b':10, 'c': 11}
>>> z = x.update(y)
>>> print z
None
>>> x
{'a': 1, 'b': 10, 'c'...
I am a novice programmer who is trying to teach myself to code, specifically in C#. I've taken on a project from a friend of mine and I am not sure what I need to know to get the project done. I suppose the issue is I don't know what I need to know to even get the project started.
I do have many of the basics of object oriented programm...
public static IList<T> LoadObjectListAll<T>()
{
ISession session = CheckForExistingSession();
var cfg = new NHibernate.Cfg.Configuration().Configure();
var returnList = session.CreateCriteria(typeof(T));
var list = returnList.List();
var castList = list.Cast<typeof(T)>();
return castList;
}
So, I'm getting a bui...
Simple question, but one that I've been curious about...is there a functional difference between the following two commands?
String::class
String.class
They both do what I expect -- that is to say they return Class -- but what is the difference between using the :: and the .?
I notice that on those classes that have constants defined...
I have been using Python more and more, and I keep seeing the variable __all__ set in different __init__.py files. Can someone explain what this does?
...
For me usable means that:
it's being used in real-wold
it has tools support. (at least some simple editor)
it has human readable syntax (no angle brackets please)
Also I want it to be as close to XML as possible, i.e. there must be support for attributes as well as for properties. So, no YAML please. Currently, only one matching lan...