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...
I've been doing c# for a long time, and have never come across an easy way to just new up a hash.
I've recently become acquainted with the ruby syntax of hashes and wonder, does anyone know of a simple way to declare a hash as a literal, without doing all the add calls.
{ "whatever" => {i => 1}; "and then something else" => {j => 2}};
...
This is an excerpt of code from a class I am working with in Java (below). Obviously the code is defining a static variable named EPSILON with the data type double. What I don't understand is the "1E-14" part. What kind of number is that? What does it mean?
final double EPSILON = 1E-14;
...
I'm writing a WinForms app which has two modes: console or GUI. Three projects within the same solution, one for the console app, one for the UI forms and the third to hold the logic that the two interfaces will both connect too. The Console app runs absolutely smoothly.
A model which holds the user-selections, it has an IList<T> wher...
"foo" instanceof String //=> false
"foo" instanceof Object //=> false
true instanceof Boolean //=> false
true instanceof Object //=> false
false instanceof Boolean //=> false
false instanceof Object //=> false
// the tests against Object really don't make sense
Array literals and Object literals match...
[0,1] instanceof Array //=> t...
Very basic question.. how do I write a short literal in C++?
I know the following:
2 is an int
2L is a long
2LL is a long long
2.0f is a float
2.0 is a double
'\2' is a char.
But how would I write a short literal? I tried 2S but that gives a compiler warning.
...
You'll have to forgive my ignorance, but I'm not used to using wide character sets in c++, but is there a way that I can use wide string literals in c++ without putting an L in front of each literal?
If so, how?
...
I always try to avoid to return string literals, because I fear they aren't defined outside of the function. But I'm not sure if this is the case. Let's take, for example, this function:
const char *
return_a_string(void)
{
return "blah";
}
Is this correct code? It does work for me, but maybe it only works for my compiler (gcc). ...
Delphi strings use single quotes, for example 'a valid string'. How does one specify the ' character within a literal string? How would one refer to the null byte (Unicode code point U+0000)?
...
Hi Guys,
I have a repeater that should show a bound field value only if it exists. Having read this post I decided to do it by using a literal within my repeater and using the OnItemDatabound trigger to populate my literal but my literal doesn't seem to be accessible from the c# code behind and I don't understand why!
Heres the aspx pa...
Consider the following:
int ival = 1.01;
int &rval = 1.01; // error: non-const reference to a const value.
int &rval = ival;
rval = 1.01;
The first assignment of &rval to a literal value fails as expected. If I comment out that line the code compiles and runs. I understand why the initialization fails, but I'm confused why the assi...
Similar to Is hard-coding literals ever acceptable?, but I'm specifically thinking of "magic strings" here.
On a large project, we have a table of configuration options like these:
Name Value
---- -----
FOO_ENABLED Y
BAR_ENABLED N
...
(Hundreds of them).
The common practice is to call a generic function to test an ...
I'm starting on a project where strings are written into the code most of the time. Many strings might only be used in a few places but some strings are common throughout many pages.
Is it a good use of my time to refactor the literals into constants being that the app is pretty well established and runs well? What would be the long-t...
Technically, any odd number of backslashes, as described in the docs.
>>> r'\'
File "<stdin>", line 1
r'\'
^
SyntaxError: EOL while scanning string literal
>>> r'\\'
'\\\\'
>>> r'\\\'
File "<stdin>", line 1
r'\\\'
^
SyntaxError: EOL while scanning string literal
It seems like the parser could just treat bac...
Hi All,
I have a user control that displays a list of categories. In that user control I have a literal control that I would like to write to from the code behind file. This is my literal
How can I get access to write to the user control? What code would I need. I keep getting this error:
Object reference not set to an instance of an...
I'm writing some code against a C++ API that takes vectors of vectors of vectors, and it's getting tedious to write code like the following all over the place:
vector<string> vs1;
vs1.push_back("x");
vs1.push_back("y");
...
vector<string> vs2;
...
vector<vector<string> > vvs1;
vvs1.push_back(vs1);
vvs1.push_back(vs2);
...
vector<vector<...
I am new to ruby and looking for a way to create a "payload" of random binary data.
def payload_grow(payload_stack)
payload = payload_stack
valid_chars = ("a".."f").to_a + ("0".."9").to_a
length = valid_chars.size
hex_code = ""
hex_code << valid_chars[rand(length-1)]
hex_code
payload = payload + '0x' + hex_code + hex_code
...
I'm trying to dynamically add results to this display and I simply want to put a break tag after a label to start putting information on the next line. For some reason, Using a literal isn't working for me. Is there a better way to do this or should I just use tables?
Dim break As LiteralControl
break = New LiteralControl("<br />")
di...
Hello,
I have multiple literals on a page. For example,
<asp:Literal id="Label1" runat="server" />
I have around 10 of these on one page and want to fill them all with the same value. Is there a good way to do that without referencing the id for each control?
...
Hi,..simple questions I think
I am trying to search for the occurrence of a string in another string using regex in javascript like so:
var content ="Hi, I like your Apartment. Could we schedule a viewing? My phone number is: ";
var gent = new RegExp("I like your Apartment. Could we schedule a viewing? My", "g");
if(content.sear...