'shift'에 해당되는 글 1건

  1. 2007.01.11 [C/C++] Remind! '>>' extends sign bit

[C/C++] Remind! '>>' extends sign bit

Language/C&C++ 2007.01.11 00:00
[[ blog 이사 과정에서 정확한 posting날짜가 분실됨. 년도와 분기 정도는 맞지 않을까? ]]

'shift' operator in C extends sign bit.

int a = 0xffffffff;
a = a>>8; // a == 0xffffffff

Due to sign of 'a' is minus, '>>8' preserve it's sign.
But, 'unsigned' value is always '>=0' So, sign bit doesn't need to be extended. So, front parts is filled with '0'.

unsigned int a = 0xffffffff
a = a >>8; // a == 0x00ffffff
신고
tags : ,
Trackback 0 : Comment 0

티스토리 툴바