Pretend you're at an interview. The interviewer asks:
What is the decimal value of this binary number?
10110101
What is the first thing you responsed with?
News reports such as this one indicate that the above number may have arisen as a programming bug.
A man in the United States popped out
to his local petrol station to buy a
pack of cigarettes - only to find his
card charged $23,148,855,308,184,500.
That is $23 quadrillion (£14
quadrillion) - many times the US
national debt.*
In hex it's $523DC2E199EBB4 which doesn't appear terribly interesting at first sight.
Anyone have any thoughts about what programming error would have caused this?
What is the total number of comparisons necessary to locate all the n sorted distinct integers in an array using binary search, I think it is nlogn, but I am not sure. What do u guys think?
I need to count the number of files in a directory using Python.
I guess the easiest way is len(glob.glob('*')), but I also count the directory as file.
Is there any way to count only the files in a directory?
I need to design a function to return negative numbers unchanged but should add a + sign at the start of the number if its already no present.
Example:
Input Output
----------------
+1 +1
1 +1
-1 -1
It will get only numeric input.
function formatNum($num)
{
# something here..perhaps a regex?
}
This function is going to be called several times in echo/print so the quicker the better.
If I want to pass a number of values for the ParamArray arglist via an array, how do I do it? From what I've read so far, on VBA, it appears that I need to explicitly list the values that I want to pass. But what if there are potentially different numbers of values to pass, so I do not know in advance how many I'll want to pass to the function? Is there not some way of using an array (a one-dimensional array) with a variable dimension?
I need to store phone numbers starting with 0 but whenever i try to store this in MySql table the starting ZERO is removed because no number start with Zero actually
how i can solve this problem please do i need to change the field type from Integer to another type
please help
Hi, I am writing a function in which I need to read a string contains floating point number and turn it back to Rational. But When I do toRational (read input :: Double), it will not turn for eg: 0.9 into 9 % 10 as expected, but instead 81..... % 9007...
Thx
Hi,
Im trying to limit the number of returned results manually in a copy of the list.phtml template, but its turning out to be alot harder than I anticipated.
Ive tried manually setting the collection size, but ya once again nothing working. Can someone show me how to do this? Would be nmuch appreciated!
I would like to know the number of users logged into my ASP.NET 2.0 application.
Points to be considered:
1) Simplest way would be to use Application or Cache object to have the counts on Session start or end. However this would fail if there is a worker process recycle. Wouldn't it?
2) Should't make a difference whether the session is inproc/state server managed/ or SQL server managed.
3) Should preferably be seamless to a web-farm architecture.
Hi
I am trying to use the following regular expression to check whether a string is a positive number with either zero decimal places, or 2:
^\d+(\.(\d{2}))?$
When I try to match this using preg_match, I get the error:
Warning: preg_match(): No ending delimiter '^' found in /Library/WebServer/Documents/lib/forms.php on line 862
What am I doing wrong?
in JavaScript, the typical way to round a number to N decimal places is something like:
function round_number(num, dec) {
return Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
}
However this approach will round to a maximum of N decimal places while I want to always round to N decimal places. For example "2.0" would be rounded to "2".
Any ideas?
I'm using a MySQL database and accessing it through Java.
PreparedStatement prep1 = this.connection.prepareStatement("UPDATE user_table
SET Level = 'Super'
WHERE Username = ?");
prep1.setString(1, username);
The update statement above works fine however I'd like to get the number of rows affected with this statement. Is this possible please?
I have some unit tests that need an X11 display so I plan to start Xvfb before running them, but to start Xvfb I will need a free display number to connect it to. My best guess is to see what's free in /tmp/.X11-unix but I'm not sure how to handle the race if many tests try to start simultaneously.
sshd must do this, does anyone know how?
How can I insert in a database the number of days of the year and at the same time insert in the same record the month, day of the month, and the day of the week?
This is my table:
tabela/coluna.Dias_ano(registo 1...365)
Year:=StrToInt(ano.Text);
diasano.Text:= IntToStr( DaysInAYear(Year) );
diasAno| Mes |diames |dia semana |
1 | janeiro | 1 |Segunda |
2 | janeiro | 2 | Terça |
...
365 | Dezembro | 31 | Segunda
I have a number of textboxes that will be displayed with their existing values. I want my servlet to be able to get all their values and then update the database with the the values that have changed.
How do I get the values? Is there some way to put them into a HashMap with the id or name as the key and the value of the textbox as the value for the key?
I want to save and restore the window position of my WPF application. I want to make the code robust to use with multiple monitors who's number and relative location can change (I want to avoid opening my application off-screen when the monitor configuration has changed inbetween invocations).
I know of the Screen class in System.Windows.Forms, but I don't want to take a dependency on that assembly just for this feature.
Hi All,
I am trying to create a console application that reads number from a file all underneath each other like so:
101
9
and then outputs into another file the closest palindrome number. So far what I have is not quite rightm i.e. I don't think I can put the class inside a method which is a bit more Java I was wandering if anyone could help at all?
Thanks :)
namespace PalidromeC
{
class Program
{
static public void Main(string[] args)
{
#region WriteAnswers
try
{
StreamWriter sw = new StreamWriter("C://Temp/PalindromeAnswers.txt");
sw.WriteLine("Answers");
sw.Close();
}//try
catch (Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}//catch
#endregion
#region ReadFile
try
{
string numbers;
StreamReader sr = new StreamReader("C://Temp/Palindrome.txt");
numbers = sr.ReadLine();
while (numbers != null)
{
Console.WriteLine(numbers);
numbers = sr.ReadLine();
}//while
sr.Close();
Console.ReadLine();
}//try
catch (Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}//catch
#endregion
NearPalindromeFinder f = new NearPalindromeFinder();
int palindrome = f.findNearPalindrome(n);
Console.WriteLine("Nearest Palindrome = " + palindrome);
}//main
public static void testFindNearestPalindrome(int n)
{
class NearPalindromeFinder
{
int findNearPalindrome(int start)
{
if (testPalindrome(start))
return start;
else
{
int neg = start;
int pos = start;
for (int i = 0; i < start; i++)
{
if (testPalindrome(start-i))
{
neg = start-i;
break;
}//if
if (testPalindrome(start+i))
{
pos = start+i;
break;
}//if
}//for
return (start == neg) ? pos : neg;
}//else
}//findNearPalindrome
bool testPalindrome(int start)
{
if (start == 0 || start == 1)
return true;
String str = String.valueOf(start);
String rev = new
if (str.equals(rev))
return true;
else
return false;
}//testPalindrome
}//NearPalindromeFinder class
}//testFindNearestPalindrome
}//Program Class
Hi All,
RAID6 is intended to provide fault tolerance in the event 2 disks fail.
What is the minimum number of disks required to implement RAID6?
thanks
How do I efficiently create a rock-scissors-paper game for n elements,
where n is any odd number =3.
In other words, I want a non-transitive complete ordering of n elements
such that each element is greater than (n-1)/2 other elements and each
element is lesser than (n-1)/2 other elements.
I have a mysql database which allocate:
iid, name, description, url, namecategory, idcategory, nametopic, idtopic
How can i know the number of entries that has categoryid=1 and topicid=1?
I've try
$result = mysql_query("SELECT COUNT(id) FROM videos WHERE categoryid=1 AND topicid=1")
But it hasn't worked!
Hi,
I have a check out form where number of products can be "n". So how i can know how many input fields are in the form and take input from it?
Thanks