Hi,
My doubt is that..lets say we have an usigned int.If I do a left shift by 32 bits...I'm getting back the original one..shouldnt it be all zeros??
According the the C++ standard (Section 5.8 para 1 "Shift operators") "The behavior is undefined if the right operand is negative, or greater than or equal to the length in bits of the promoted left operand."
In other words, assuming your unsigned type is 32 bits, you are not allowed to do a left shift of more than 31 bits. Anything is allowed to happen if you do. If you do a single left-shift 32 times (as opposed to a single 32-bit shift) the variable will be zero-filled.
ok..great..thanks
Good grief, why the plethora of new threads?
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.