integer

Emulating int64 overflows in Ruby

邮差的信 提交于 2019-12-20 05:53:36
问题 I'm a long time programmer but new to Ruby. I'm trying to port an algorithm called CheckRevision used for checking integrity of game files before loggin into Battle.net's online gaming service. The algorithm makes a "hash" of the files with a given formula. Without boring details, it's constantly modifying the values a , b and c which are 64-bit integers, or in the reference implementation I'm porting from, a Java long . My implementation is correct for the first few iterations but when the

convert pointer string to integer

江枫思渺然 提交于 2019-12-20 05:26:38
问题 I am trying to convert treePtr->item.getInvest() which contains a string to an integer. Is this possible? 回答1: #include <sstream> // ... string str(*(treePtr->item.getInvest())); // assuming getInvest() returns ptr istringstream ss(str); int the_number; ss >> the_number; 回答2: if you have access to boost: int number= boost::lexical_cast<int>(treePtr->item.getInvest()); 回答3: Better to use strtol() than mess around with streams. const char* s = treePtr->item.getInvest(); const char* pos; long

x64 bit assembly

天大地大妈咪最大 提交于 2019-12-20 05:21:49
问题 I started assembly (nasm) programming not too long ago. Now I made a C function with assembly implementation which prints an integer. I got it working using the extended registers, but when I want to write it with the x64 registers (rax, rbx, ..) my implementation fails. Does any of you see what I missed? main.c: #include <stdio.h> extern void printnum(int i); int main(void) { printnum(8); printnum(256); return 0; } 32 bit version: ; main.c: http://pastebin.com/f6wEvwTq ; nasm -f elf32 -o

x64 bit assembly

≡放荡痞女 提交于 2019-12-20 05:21:42
问题 I started assembly (nasm) programming not too long ago. Now I made a C function with assembly implementation which prints an integer. I got it working using the extended registers, but when I want to write it with the x64 registers (rax, rbx, ..) my implementation fails. Does any of you see what I missed? main.c: #include <stdio.h> extern void printnum(int i); int main(void) { printnum(8); printnum(256); return 0; } 32 bit version: ; main.c: http://pastebin.com/f6wEvwTq ; nasm -f elf32 -o

Check if variable is a number and positive integer in PHP?

这一生的挚爱 提交于 2019-12-20 05:15:06
问题 For example, say: <?php // Grab the ID from URL, e.g. example.com/?p=123 $post_id = $_GET['p']; ?> How do I check if variable $post_id is a number, and a positive integer at that (i.e. 0-9, not a floating point number, fraction, or a negative number)? EDIT: Can't use is_int 'cause $_GET returns a string. Think I need to use intval() or ctype_digit(), with the latter seeming more appropriate. For example: if( ctype_digit( $post_id ) ) { ... } 回答1: To check if a string input is a positive

Get integer value from edittext

狂风中的少年 提交于 2019-12-20 04:42:07
问题 When I try to run the code below, my program has stops. I want this code to get the value from edittext but it´s not working as I expected it. What am I doing wrong? public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button sum = (Button) findViewById(R.id.button1); Button cancel = (Button) findViewById(R.id.button2); final EditText from = (EditText) findViewById(R

Odd behaviour of Python tokenizer when parsing integer numbers

让人想犯罪 __ 提交于 2019-12-20 04:19:33
问题 I noticed the following fact with CPython3 and Pypy3, contrasting with the behaviour of both CPython2 and Pypy2: In Python3, it looks like leading zeros when parsing code yield an error except for a very single number wich is 0 . Thus 00 is valid but not 042 . In Python2, leading zeros are allowed for all integers. Thus 00 and 042 are valid. Why did Python change its behaviour between both versions? 回答1: Python 3 standardized how all integer literals (other than base 10) were defined: 0?dddd.

South migrate DateField to IntegerField

喜夏-厌秋 提交于 2019-12-20 02:54:27
问题 I want to change my Model class Source(models.Model): release_date = models.DateField() to class Source(models.Model): release_date = models.IntegerField() as expected, I get an error django.db.utils.DataError: (1264, "Out of range value for column 'release_date' at row 1") What I actually want is, to only save the year in the IntegerField as that is all I need. Is there a very intelligent way to take existing dates' year field and migrate it to the new IntegerField by altering the method def

Maximum integer in Perl

泄露秘密 提交于 2019-12-20 02:52:23
问题 Set $i=0 and do ++$i while it increases. Which number we would reach? Note that it may be not the same as maximum integer in Perl (as asked in the title), because there may be gaps between adjacent integers which are greater than 1 . 回答1: "Integer" can refer to a family of data types ( int16_t , uint32_t , etc). There's no gap in the numbers these can represent. "Integer" can also refer to numbers without a fractional component, regardless of the type of the variable used to store it. ++ will

Java printing a string containing multiple integers

给你一囗甜甜゛ 提交于 2019-12-20 02:38:10
问题 Just starting learning java today and can't seem to figure this out. I am following the tutorial on learnjavaonline.org which teaches you a few things and then asks you to write a code to do a specific thing, it then checks the output to see if its correct. The thing is, if its not correct, it doesn't say why, or give you an example of the correct code. It wants me to output a string saying "H3110 w0r1d 2.0 true" using all of the primitives i came up with this public class Main { public