integer

CPAN modules for computing integer hash keys based on short strings

I'm looking for a CPAN module that will take a short string: my $hash_value = hash_this('short string not too long'); And hash it into an integer key: say $hash_value; 12345671234 # an integer key ...

Fastest way to calculate the decimal length of an integer? (.NET)

I have some code that does a lot of comparisons of 64-bit integers, however it must take into account the length of the number, as if it was formatted as a string. I can't change the calling code, only the function. The easiest way (besides .ToString().Length) is: (int)Math.Truncate(Math.Log10(x)) + 1; However that performs rather po...

How to declarate LARGE_INTEGER in C#

Hello, the code below(in C++) is what I am trying the convert into C# DWORD Func_X_4(DWORD arg1, DWORD arg2, DWORD arg3) { LARGE_INTEGER result = {1, 0}; LARGE_INTEGER temp1 = {0}; LARGE_INTEGER temp2 = {0}; LARGE_INTEGER temp3 = {0}; LARGE_INTEGER temp4 = {0}; for(int x = 0; x < 32; ++x) { if(arg2 & 1) { temp1.LowPart = arg3; te...

How to read integer in Erlang?

I'm trying to read user input of integer. (like cin >> nInput; in C++) I found io:fread bif from http://www.erlang.org/doc/man/io.html, so I write code like this. {ok, X} = io:fread("input : ", "~d"), io:format("~p~n", [X]). but when I input 10, the erlang terminal keep giving me "\n" not 10. I assume fread automatically read 10 ...

Format a number as a string

How do you format a number as a string so that it takes a number of spaces in front of it? I want the shorter number 5 to have enough spaces in front of it so that the spaces plus the 5 have the same length as 52500. The procedure below works, but is there a built in way to do this? a = str(52500) b = str(5) lengthDiff = len(a) - len(...

How can I convert a character to a integer in Python, and viceversa?

I want to get, given a character, its ascii value. For example, for the character 'a', I want to get 97, and viceversa. Thanks, Manuel ...

Faulty C# code involving doubles and integers.

for (iy = 0; iy < h; iy++) { double angy = (camera.fov_y / h) * iy; for (ix = 0; ix < w; ix++) { double angx = (camera.fov_x / w) * ix; //output[ix,iy].r = (int)Math.Round(255 * (angy / camera.fov_y); //output[ix,iy].b = (int)Math.Round(255 * (angy / camera.fov_y); ...

Converting byte-stream into numeric data-type

Let's say I have a byte-stream in which I know the location of a 64-bit value (a 64-bit nonce). The byte-order is Little-Endian. As PHP's integer data-type is limited to 32-bit (at least on 32-bit operating systems) how would I convert the byte-sequence into a PHP numeric representation (float would be sufficient I think)? $serverChalle...

C integer overflow behaviour when assigning to larger-width integers

If I execute the following code in C: #include <stdint.h> uint16_t a = 4000; uint16_t b = 8000; int32_t c = a - b; printf("%d", c); It correctly prints '-4000' as the result. However, I'm a little confused: shouldn't there be an arithmetic overflow when subtracting a larger unsigned integer from the other? What casting rules are ...

decimals, ints, casting... oh my!

I'm going through the "Head First C#" book and in one of the chapters I created a program and uses variables declared as ints and decimals. Visual Studio got cranky with me a couple of times about mixing and matching the two. For example: dinnerParty.NumberOfPeople = (int) numericUpDown1.Value; NumberOfPeople is declared as an int an...

Add and Subtract 128 Bit Integers in C(++)

Hello :) I'm writing a compressor for a long stream of 128 bit numbers. I would like to store the numbers as differences -- storing only the difference between the numbers rather than the numbers themselves because I can pack the differences in fewer bytes because they are smaller. However, for compression then I need to subtract these...

Echoing an integer from a mySQL database

Hi I'm trying to make a website in which a user inputs details on one screen, and they are posted onto the following script. This script is meant to store these details in a database along with a unique integer ID (which it does), and then generate two links containing the unique ID of the record just created. Since the database creates...

How do I spell out an integer in Ruby?

Does anyone know of a Ruby module that will take an integer and spell it out ( 1 => "one", 2 => "two", etc..)? ...

Comparing a float to an integer in C

Can I compare a floating-point number to an integer? Will the float compare to integers in code? float f; // f has a saved predetermined floating-point value to it if (f >=100){__asm__reset...etc} Also, could I... float f; int x = 100; x+=f; Sorry, I don't have a lot of experience using floating point. But ultimately I ha...

PHP - Large Interger mod calculation

I need to calculate modulus with large number like : <?php $largenum = 95635000009453274121700; echo $largenum % 97; ?> It's not working... beacause $largenum is too big for an int in PHP. Any idea how to do this ? ...

Computing (a*b) mod c quickly for c=2^N +-1

In 32 bit integer math, basic math operations of add and multiply are computed implicitly mod 2^32, meaning your results will be the lowest order bits of the add or multiply. If you want to compute the result with a different modulus, you certainly could use any number of BigInt classes in different languages. And for values a,b,c < 2^3...

C#: How do i assign many variables with an integer(i) in for loop?

Hello, Imagine we have 5 string variables and we want to assign "Foo" to them during runtime. Instead of this string a1 = "Foo"; string a2 = "Foo"; string a3 = "Foo"; string a4 = "Foo"; string a5 = "Foo"; Can't we use something like this: for(int i = 0;i < 5;i++) { a+i = "Foo"; } Is it impossible to access them in a similiar ...

Convert a number to a list of integers

How do I write the magic function below? >>> num = 123 >>> lst = magic(num) >>> >>> print lst, type(lst) [1, 2, 3], <type 'list'> ...

BugHunt - Javascript Parsing error?

Hello there, peoples of web! Maybe one of you will spot what's amiss in the following function: It is a javascript function used on a textbox client-side onblur event to validate that the entered text represents a correctly formatted and valid date. I tried a few times, and it worked, but it seems ! should've tried all dates! it will ...

Algorithm to find the smallest non negative integer that is not in a list

Given a list of integers, how can I best find an integer that is not in the list? The list can potentially be very large, and the integers might be large (i.e. BigIntegers, not just 32-bit ints). If it makes any difference, the list is "probably" sorted, i.e. 99% of the time it will be sorted, but I cannot rely on always being sorted. ...