signed-integer

What is going on with bitwise operators and integer promotion?

℡╲_俬逩灬. 提交于 2019-11-28 01:51:19
I have a simple program. Notice that I use an unsigned fixed-width integer 1 byte in size. #include <cstdint> #include <iostream> #include <limits> int main() { uint8_t x = 12; std::cout << (x << 1) << '\n'; std::cout << ~x; std::cin.clear(); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); std::cin.get(); return 0; } My output is the following. 24 -13 I tested larger numbers and operator << always gives me positive numbers, while operator ~ always gives me negative numbers. I then used sizeof() and found... When I use the left shift bitwise operator( << ), I receive an

What is the difference between signed and unsigned int

自作多情 提交于 2019-11-27 10:43:29
What is the difference between signed and unsigned int? Bill Evans at Mariposa As you are probably aware, int s are stored internally in binary. Typically an int contains 32 bits, but in some environments might contain 16 or 64 bits (or even a different number, usually but not necessarily a power of two). But for this example, let's look at 4-bit integers. Tiny, but useful for illustration purposes. Since there are four bits in such an integer, it can assume one of 16 values; 16 is two to the fourth power, or 2 times 2 times 2 times 2. What are those values? The answer depends on whether this

What is going on with bitwise operators and integer promotion?

不羁岁月 提交于 2019-11-26 22:01:20
问题 I have a simple program. Notice that I use an unsigned fixed-width integer 1 byte in size. #include <cstdint> #include <iostream> #include <limits> int main() { uint8_t x = 12; std::cout << (x << 1) << '\n'; std::cout << ~x; std::cin.clear(); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); std::cin.get(); return 0; } My output is the following. 24 -13 I tested larger numbers and operator << always gives me positive numbers, while operator ~ always gives me negative numbers

What is the difference between signed and unsigned int

。_饼干妹妹 提交于 2019-11-26 15:16:39
问题 What is the difference between signed and unsigned int? 回答1: As you are probably aware, int s are stored internally in binary. Typically an int contains 32 bits, but in some environments might contain 16 or 64 bits (or even a different number, usually but not necessarily a power of two). But for this example, let's look at 4-bit integers. Tiny, but useful for illustration purposes. Since there are four bits in such an integer, it can assume one of 16 values; 16 is two to the fourth power, or

Displaying numbers with DOS

只愿长相守 提交于 2019-11-26 14:47:53
I was tasked to write a program that displays the linear address of my program's PSP. I wrote the following: ORG 256 mov dx,Msg mov ah,09h ;DOS.WriteStringToStandardOutput int 21h mov ax,ds mov dx,16 mul dx ; -> Linear address is now in DX:AX ??? mov ax,4C00h ;DOS.TerminateWithExitCode int 21h ; ------------------------------ Msg: db 'PSP is at linear address $' I searched the DOS api (using Ralph Brown's interrupt list ) and didn't find a single function to output a number! Did I miss it, and what can I do? I want to display the number in DX:AX in decimal. Sep Roland It's true that DOS doesn