Counting trailing ones and zeros in binary representation of a number in Julia – trailing_ones() and trailing_zeros() Methods
Last Updated :
26 Mar, 2020
The trailing_ones()
is an inbuilt function in julia which is used to find the number of ones trailing the binary representation of the specified number.
Syntax: trailing_ones(x::Integer)
Parameters:
- x::Integer: Specified integer number.
Returns: It returns the number of ones trailing the binary representation of the specified number.
Example:
println(trailing_ones( 2 ))
println(trailing_ones( 15 ))
println(trailing_ones( 13 ))
println(trailing_ones( 3 ))
|
Output:
0
4
1
2
trailing_zeros()
The trailing_zeros()
is an inbuilt function in julia which is used to find the number of zeros trailing the binary representation of the specified number.
Syntax: trailing_zeros(x::Integer)
Parameters:
- x::Integer: Specified integer number.
Returns: It returns the number of zeros trailing the binary representation of the specified number.
Example:
println(trailing_zeros( 2 ))
println(trailing_zeros( 56 ))
println(trailing_zeros( 100 ))
println(trailing_zeros( 32 ))
|
Output:
1
3
2
5
Share your thoughts in the comments
Please Login to comment...