integer

Why are the results of integer promotion different?

十年热恋 提交于 2019-12-17 19:37:42
问题 Please look at my test code: #include <stdlib.h> #include <stdio.h> #define PRINT_COMPARE_RESULT(a, b) \ if (a > b) { \ printf( #a " > " #b "\n"); \ } \ else if (a < b) { \ printf( #a " < " #b "\n"); \ } \ else { \ printf( #a " = " #b "\n" ); \ } int main() { signed int a = -1; unsigned int b = 2; signed short c = -1; unsigned short d = 2; PRINT_COMPARE_RESULT(a,b); PRINT_COMPARE_RESULT(c,d); return 0; } The result is the following: a > b c < d My platform is Linux, and my gcc version is 4.4

Java - how to convert letters in a string to a number?

本小妞迷上赌 提交于 2019-12-17 19:34:05
问题 I'm quite new to Java so I am wondering how do you convert a letter in a string to a number e.g. hello world would output as 8 5 12 12 15 23 15 18 12 4 . so a=1 , b=2 , z=26 etc. 回答1: Since this is most likely a learning assignment, I'll give you a hint: all UNICODE code points for the letters of the Latin alphabet are ordered alphabetically. If the code of a is some number N , then the code of b is N+1 , the code of c is N+2 , and so on; the code of Z is N+26 . You can subtract character

Could not find an overload for '*' that accepts the supplied argument

家住魔仙堡 提交于 2019-12-17 19:24:01
问题 I have converted a String to an Int by by using toInt() . I then tried multiplying it by 0.01, but I get an error that says Could not find an overload for '*' that accepts the supplied argument. Here is my code: var str: Int = 0 var pennyCount = 0.00 str = pennyTextField.text.toInt()! pennyCount = str * 0.01 From reading other posts it seems that the answer has to do with the type. For example if the type is set as an Integer then it gets a similar error. I have tried changing the type to an

Ruby gets/puts only for strings?

时间秒杀一切 提交于 2019-12-17 18:36:59
问题 I'm new to Ruby and am currently working on some practice code which looks like the following: puts 'Hello there, Can you tell me your favourite number?' num = gets.chomp puts 'Your favourite number is ' + num + '?' puts 'Well its not bad but ' + num * 10 + ' is literally 10 times better!' This code however just puts ten copies of the num variable and doesn't actually multiply the number so I assume I need to make the 'num' variable an integer? I've had no success with this so can anyone show

Why does Python 3 allow “00” as a literal for 0 but not allow “01” as a literal for 1?

∥☆過路亽.° 提交于 2019-12-17 17:53:33
问题 Why does Python 3 allow "00" as a literal for 0 but not allow "01" as a literal for 1? Is there a good reason? This inconsistency baffles me. (And we're talking about Python 3, which purposely broke backward compatibility in order to achieve goals like consistency.) For example: >>> from datetime import time >>> time(16, 00) datetime.time(16, 0) >>> time(16, 01) File "<stdin>", line 1 time(16, 01) ^ SyntaxError: invalid token >>> 回答1: Per https://docs.python.org/3/reference/lexical_analysis

How to display hexadecimal numbers in C?

北战南征 提交于 2019-12-17 17:29:07
问题 I have a list of numbers as below: 0, 16, 32, 48 ... I need to output those numbers in hexadecimal as: 0000,0010,0020,0030,0040 ... I have tried solution such as: printf("%.4x",a); // where a is an integer but the result that I got is: 0000, 0001, 0002, 0003, 0004 ... I think I'm close there. Can anybody help as I'm not so good at printf in C. Thanks. 回答1: Try: printf("%04x",a); 0 - Left-pads the number with zeroes (0) instead of spaces, where padding is specified. 4 (width) - Minimum number

C - How to check if the number is integer or float? [closed]

家住魔仙堡 提交于 2019-12-17 16:53:34
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 years ago . Exercise 30 Write a program which reads float value developed as decimal extension and If it's integer, it says that it's integer on the other hand it rounds it to integer and writes the result. Remember about data control Here's the new one without this message about integer type. #include <stdio

Convert string to int. x86 32 bit Assembler using Nasm

左心房为你撑大大i 提交于 2019-12-17 16:52:41
问题 So I'm trying to convert a string to a number so I can add another number to it later. here is what I have to far in my .text for the conversion. num2Entered is what the user entered. Num1plusNum2 is the label that I will eventually add to. They are both declared in the .bss section. Any help would be appreciated! mov ax, [num2Entered + 0] sub ax, '0' mov bx, WORD 1000 mul bx mov [Num1plusNum2], ax mov ax, [num2Entered + 1] sub ax, '0' mov bx, WORD 100 mul bx add [Num1plusNum2], ax mov ax,

Most efficient way to check if all __m128i components are 0 [using <= SSE4.1 intrinsics]

风流意气都作罢 提交于 2019-12-17 16:44:40
问题 I am using SSE intrinsics to determine if a rectangle (defined by four int32 values) has changed: __m128i oldRect; // contains old left, top, right, bottom packed to 128 bits __m128i newRect; // contains new left, top, right, bottom packed to 128 bits __m128i xor = _mm_xor_si128(oldRect, newRect); At this point, the resulting xor value will be all zeros if the rectangle hasn't changed. What is then the most efficient way of determining that? Currently I am doing so: if (xor.m128i_u64[0] | xor

How do I explode an integer

巧了我就是萌 提交于 2019-12-17 16:43:40
问题 the answer to this could be easy. But I'm very fresh to programming. So be gentle... I'm at work trying to do a quick fix for one of your customers. I want to get the total numbers of digits in a integer, and then explode the integer: rx_freq = 1331000000 ( = 10 ) $array[0] = 1 $array[1] = 3 . . $array[9] = 0 rx_freq = 990909099 ( = 9 ) $array[0] = 9 $array[1] = 9 . . $array[8] = 9 I'm not able to use explode, as this function need a delimiter. I've searched the eyh'old Google and