Check if the Kth bit it set!

Example 1:
n= 5
k = 1
binary representation of 5 : 101
1st bit from right is set
therefore output = YES

Example 2:
n = 8
k = 2
binary representation of 8 : 1000
2nd bit from right is not set
therefore output = NO

Solution using Left Shift operator:


This content originally appeared on DEV Community and was authored by hebaShakeel

Example 1:
n= 5
k = 1
binary representation of 5 : 101
1st bit from right is set
therefore output = YES

Example 2:
n = 8
k = 2
binary representation of 8 : 1000
2nd bit from right is not set
therefore output = NO

Solution using Left Shift operator:
Image description

Solution using Right Shift Operator:
Image description


This content originally appeared on DEV Community and was authored by hebaShakeel


Print Share Comment Cite Upload Translate Updates
APA

hebaShakeel | Sciencx (2022-06-19T15:34:31+00:00) Check if the Kth bit it set!. Retrieved from https://www.scien.cx/2022/06/19/check-if-the-kth-bit-it-set/

MLA
" » Check if the Kth bit it set!." hebaShakeel | Sciencx - Sunday June 19, 2022, https://www.scien.cx/2022/06/19/check-if-the-kth-bit-it-set/
HARVARD
hebaShakeel | Sciencx Sunday June 19, 2022 » Check if the Kth bit it set!., viewed ,<https://www.scien.cx/2022/06/19/check-if-the-kth-bit-it-set/>
VANCOUVER
hebaShakeel | Sciencx - » Check if the Kth bit it set!. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/06/19/check-if-the-kth-bit-it-set/
CHICAGO
" » Check if the Kth bit it set!." hebaShakeel | Sciencx - Accessed . https://www.scien.cx/2022/06/19/check-if-the-kth-bit-it-set/
IEEE
" » Check if the Kth bit it set!." hebaShakeel | Sciencx [Online]. Available: https://www.scien.cx/2022/06/19/check-if-the-kth-bit-it-set/. [Accessed: ]
rf:citation
» Check if the Kth bit it set! | hebaShakeel | Sciencx | https://www.scien.cx/2022/06/19/check-if-the-kth-bit-it-set/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.