I have an integer n
, and I'd like to truncate the last two digits of the number using only bitwise operations.
So, in regular arithmetic, it'd be as simple as n /= 100
. But how would this be done with bitwise operation(s)?
Thanks,
(This is in c++, by the way)
[Edit]: For instance, given the number 1234
, I'd like to get 12
. (truncate the last two digits 34
)
[Edit2:] Let me rephrase the question. I'm trying to understand why a particular function that's supposed to truncate the last two digits of a number kind of screws things up when given a negative input. (And I don't have the code for this function)
Here's the set of inputs and their corresponding outputs
-200901 ==> 186113241
-200801 ==> 186113242
-200701 ==> 186113243
-200601 ==> 186113244
-190001 ==> 186113350
-190101 ==> 186113349
-190201 ==> 186113348
-190301 ==> 186113347