about | help | code help+videos | done | prefs |
Write a method that performs a bit-wise logic-shift-right on the binary representation of the integer input parameter. Return an array with two elements. The first element in the array is the integer representation of the resulting binary number after performing the logic-shift-right. The second element is the "overflow" value. For example, if the input parameter is 23, the binary representation for that is 10111. After logic-shifting-right, you would have 1011 (each binary digit being shifted right one position). However, the right-most digit is lost. That digit needs to be returned in the second element of the returned array. So, with the input parameter value being 23, which is 10111 in binary, the logic-shift-right would produce 1011, which is 11 in decimal, with a "carry" or "overflow" (or REALLY an "underflow") value of 1. So the input of 23 would produce an output of {11,1}. As an other example, 70, which is 1000110 in binary would return {35,0} because after shifting right, you get 100011, which is 35, and the lost-bit is a zero. Look at the test data for additional examples. You may assume that the input parameter is between 0 and 65535. You may NOT use ANY strings or string methods. jan19_2018_SLHL_bitShiftRight(65535) → [32767, 1] jan19_2018_SLHL_bitShiftRight(51) → [25, 1] jan19_2018_SLHL_bitShiftRight(18) → [9, 0] ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 290
Copyright Nick Parlante 2017 - privacy