According to K&R 2nd edition the results are implementation-dependent for right shifts of signed values.
Wikipedia says that C/C++ ‘usually’ implements an arithmetic shift on signed values.
Basically you need to either test your compiler or not rely on it. My VS2008 help for the current MS C++ compiler says that their compiler does an arithmetic shift.
Related Posts:
- What is “2’s Complement”?
- How is overflow detected in two’s complement?
- Converting an integer to binary in C
- Why prefer two’s complement over sign-and-magnitude for signed numbers?
- What is Bit Masking?
- What are bitwise shift (bit-shift) operators and how do they work?
- bad operand types for binary operator “&” java
- Why unsigned int 0xFFFFFFFF is equal to int -1?
- Reading a binary file with python
- Bitwise operation |= in C
- What is the difference between signed and unsigned binary
- binary bomb lab phase 6
- Read and write to binary files in C?
- How to used the alphabet binary symbols
- What is the “biggest” negative number on a 4-bit machine?
- convert decimal numbers to excess-127 representations
- Is it possible to program in binary?
- The difference between logical shift right, arithmetic shift right, and rotate right
- How to use execvp()
- How to use execvp() to execute a command
- How does strtok() split the string into tokens in C?
- what is Segmentation fault (core dumped)? [duplicate]
- How to convert an int to string in C?
- How to print in C
- What is newline character — ‘\n’
- Why does ENOENT mean “No such file or directory”?
- What does the question mark character (‘?’) mean?
- makefile:4: *** missing separator. Stop
- C Linking Error: undefined reference to ‘main’
- Undefined reference to pthread_create
- How to reverse an std::string? [duplicate]
- What is the C version of RMI
- How to convert an int to string in C?
- How do I use extern to share variables between source files?
- Cannot assign requested address – possible causes?
- Binary numbers in Python
- error: called object is not a function or function pointer
- Is there any format specifier of bool in C?
- how to open an mp3 file with c
- munmap_chunk(): invalid pointer
- What is the difference between a static and const variable?
- How to convert string to binary?
- What is a bus error? Is it different from a segmentation fault?
- unsigned int vs. size_t
- Get the current time in C
- error: expected primary-expression before ‘)’ token (C)
- Going through a text file line by line in C
- What is activation record in the context of C and C++?
- Get text from user input using C
- How do I lowercase a string in C?
- Fastest way to check if a file exist using standard C++/C++11,14,17/C?
- warning: expression result unused
- What is the difference between exit(0) and exit(1) in C?
- Thread 1: EXC_BAD_ACCESS (code=1, address=0x0) standard C memory issue
- How to print a char array in C through printf?
- How to clear all the elements of array in C?
- 2D array vs array of arrays
- Sign extend a nine-bit number in C
- How to create an array of strings in C?
- expected expression before ‘{‘ token
- C Vector/ArrayList/LinkedList
- How can I get the list of files in a directory using C or C++?
- What are the different versions of exec used for in C and C++?
- Portable way to check if directory exists [Windows/Linux, C]
- How to convert integer to char in C?
- Regular expressions in C: examples?
- What’s the difference between * and & in C?
- Writing a simple shell in C using fork/execvp
- Difference between pic Vs pie
- What is the difference between array and enum in C ?
- How would one write object-oriented code in C?
- What integer hash function are good that accepts an integer hash key?
- X86 assembly – Handling the IDIV instruction
- Pause screen at program completion in C
- How do you clear the console screen in C?
- Difference between fgets and fscanf?
- How can I find the number of elements in an array?
- How to print (using cout) a number in binary form?
- Array type char[] is not assignable
- What is the job of autogen.sh when building a c++ package on Linux
- Lua – Number to string behaviour
- error: function returns address of local variable
- Parameter name omitted error?
- Character constant too long for its type
- Representing EOF in C code?
- Return a `struct` from a function in C
- C: scanf to array
- What are “prototypes” in a C program?
- What’s the difference between “mod” and “remainder”?
- undefined reference to `std::ios_base::Init::Init()’
- previous declaration of ‘function’ was here in C [duplicate]
- What tools are there for functional programming in C?
- typedef fixed length array
- Invalid write of size 1
- How to solve static declaration follows non-static declaration in GCC C code?
- realloc(): invalid next size when reallocating to make space for strcat on char *
- gdb: No symbol “i” in current context
- Whats the difference between UInt8 and uint8_t
- How to Compare 2 Character Arrays [duplicate]
- How to use redirection in C for file input