unsigned right shift '>>>' Operator in sql server -


how write unsigned right shift operator in sql server? expression value >>> 0

here e.g. -5381>>>0 = 4294961915

t-sql has no bit-shift operators, you'd have implement 1 yourself. there's implementation of bitwise shifts here: http://sqlblog.com/blogs/adam_machanic/archive/2006/07/12/bitmask-handling-part-4-left-shift-and-right-shift.aspx

you'd have cast integer varbinary, use bitwise shift function , cast integer , (hopefully) hey-presto! there's result you're expecting.

implementation , testing left exercise reader...

edit - try clarify have put in comments below, executing sql demonstrate different results given various casts:

select -5381 signed_integer,         cast(-5381 varbinary) binary_representation_of_signed_integer,         cast(cast(-5381 bigint) varbinary) binary_representation_of_signed_big_integer,          cast(cast(-5381 varbinary) bigint) signed_integer_transposed_onto_big_integer,          cast(cast(cast(-5381 varbinary) bigint) varbinary) binary_representation_of_signed_integer_trasposed_onto_big_integer 

results:

signed_integer binary_representation_of_signed_integer                        binary_representation_of_signed_big_integer                    signed_integer_transposed_onto_big_integer binary_representation_of_signed_integer_trasposed_onto_big_integer -------------- -------------------------------------------------------------- -------------------------------------------------------------- ------------------------------------------ ------------------------------------------------------------------ -5381          0xffffeafb                                                     0xffffffffffffeafb                                             4294961915                                 0x00000000ffffeafb 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -