Advertisement
Billy123456

Challenge

Jun 30th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. (CLOSED)
  2.  
  3.  
  4.  
  5.  
  6. (This challenge will not be used for any development purposes, these are just fun, small, challenges.)
  7. (Solutions will be posted at 7/7/2018 (day/month/year) UTC.)
  8. Implement bitwise not (see bottom for explanation of bitwise not) assuming the function toBinary exists that returns a string with extra zeros filled out (ex: if I input 10, I will get ...0010 (with the ... being 60 zeros), and we are working with 64 bits and integers. I'd like to see code with a function named bnot that I can call to get the result in base 10, NOT BINARY.
  9.  
  10. Extra challenge: Why does bitwise not with a positive number give me a negative number in return?
  11.  
  12.  
  13. Explanation on bitwise not:
  14. Bitwise not turns bits from 0 to 1 and 1 to 0. For example, if we have (assuming this is 16 bit so this doesn't get too long and the 16th bit decides whether the number is positive or negative.)
  15.  
  16. 0000 0000 0000 0000
  17. 0000 0000 0000 0111
  18.  
  19. the result will become (THE RESULT MUST BE IN BASE 10!)
  20.  
  21. 1111 1111 1111 1111
  22. 1111 1111 1111 1000
  23.  
  24. (edit)
  25. Note:
  26. To convert binary back to base 10, use tonumber(myBits, 2).
  27. (eoe) (end of edit)
  28.  
  29. DM @hiimgoodpack#6011 with questions and solutions.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement