Ad
  • Custom User Avatar
  • Default User Avatar

    I'm assuming you're asking about the left bit (aka binary) shift operators <<

    It can be confusing at first, because the same operator is overloaded by e.g. stringstream to append things to the stream.
    But originally the << and >> operators shift bits in an integer. Combined with & (and) operation, it is used here to extract 8 bit parts of the original 32 bit number.

    Take a look here https://www.educative.io/answers/what-are-bit-shift-operations . And here https://www.tutorialspoint.com/cplusplus/cpp_operators.htm .

    Given an uint32_t variable ip, you can extract four 8 bit chunks like that:

    uint8_t a = ip >> 24; // basically discard rightmost 24 bits and we're left with the leftmost 8 bits
    uint8_t b = (ip >> 16) & 0xFF; // get rid of 16 rightmost bits, and use & to mask out the 8 leftmost bits
    uint8_t c = (ip >> 8) & 0xFF; // as above, but we discard 8 rightmost bits
    uint8_t d = ip & 0xFF; // no bit shifts - the bits are in the right place, we just need to get rid of leftmost 24 bits by masking them
    

    To reverse it:

    ip = (a << 24) + (b << 16) + (c << 8) + d;
    

    Hope that helps :)

  • Custom User Avatar

    Please, help me understand how this code works. If it possible give me a tip about how to google a theory about it.

  • Custom User Avatar

    Approved. Thanks!

  • Custom User Avatar
  • Custom User Avatar

    Javascript translation added. Please review and approve.

  • Custom User Avatar

    I'm sorry, Ciprian Amza, I didn't see your changes while editing it myself. Maybe we should keep your more detailed explanation.

  • Custom User Avatar

    Changed description in following sentences:

    (N.E. does not count either as failed student or as participant at all)

    and

    The best number grade from all the participants to 1 decimal place (check above)

  • Custom User Avatar

    After the apparently not so smart decision of approving a kata whose author has been inactive for some months, I tried to clarify the description regarding the open issues.

    In this case I changed the first rule of error reporting to:

    1. First check if the list is in the correct format (e.g. number grades corresponding to the pattern #.#), if not return this error: Error Message = "Invalid list"
  • Custom User Avatar

    Thank you very much for your help. I have updated the reference solution with proper formatting. You should no longer get that warning. I tested with your solution and my solution. Neither produced a warning, and both passed all tests. Thanks for testing my kata, and providing valuable feedback.

  • Custom User Avatar

    Interesting kata. However, your reference solution gives following warning in stderr:

    Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
    

    Maybe you could change the way of parsing sentenceDate.

  • Custom User Avatar

    How about just changing the description to include those in real life maybe even more efficient solutions, too? @balygaby

  • Custom User Avatar

    I changed the tests to report

    Expected std::exception. No exception was thrown.
    
  • Custom User Avatar

    Yeah, I realized it afterwards too. However, learned some new things tonight, not only about JS's intricacies. Thank you!

  • Custom User Avatar

    I tried to improve balygaby's reference solution and test cases in this regard. Please check.

  • Loading more items...