[Question]
  [
**Problem:**
Find the number of leading zeroes in a 64-bit signed integer
**Rules:**
* The input cannot be treated as string; it can be anything where math and bitwise operations drive the algorithm
* The output should be validated against the 64-bit signed integer representation of the number, regardless of language
* [Default code golf rules apply](https://codegolf.stackexchange.com/tags/code-golf/info)
* Shortest code in bytes wins
**Test cases:**
These tests assume two's complement signed integers. If your language/solution lacks or uses a different representation of signed integers, please call that out and provide additional test cases that may be relevant. I've included some test cases that address double precision, but please feel free to suggest any others that should be listed.
```
input                output   64-bit binary representation of input (2's complement)
-1                   0        1111111111111111111111111111111111111111111111111111111111111111
-9223372036854775808 0        1000000000000000000000000000000000000000000000000000000000000000
9223372036854775807  1        0111111111111111111111111111111111111111111111111111111111111111
4611686018427387903  2        0011111111111111111111111111111111111111111111111111111111111111
1224979098644774911  3        0001000011111111111111111111111111111111111111111111111111111111
9007199254740992     10       0000000000100000000000000000000000000000000000000000000000000000
4503599627370496     11       0000000000010000000000000000000000000000000000000000000000000000
4503599627370495     12       0000000000001111111111111111111111111111111111111111111111111111
2147483648           32       0000000000000000000000000000000010000000000000000000000000000000
2147483647           33       0000000000000000000000000000000001111111111111111111111111111111
2                    62       0000000000000000000000000000000000000000000000000000000000000010
1                    63       0000000000000000000000000000000000000000000000000000000000000001
0                    64       0000000000000000000000000000000000000000000000000000000000000000
```
  
[Answer]
# x86\_64 machine language on Linux, 6 bytes
```
0:       f3 48 0f bd c7          lzcnt  %rdi,%rax
5:       c3                      ret
```
Requires Haswell or K10 or higher processor with `lzcnt` instruction.
[Try it online!](https://tio.run/##S9ZNT07@/19DK01TQ9NWKabCzTimwsQipsLALabCySWmwtkciI2VrLlyEzPzNDSruQqKMvNK0jSUVFNi8pR00jQMfTQ1rTFEDcCitf///0tOy0lML/6vW5VakZpcXJKYnA0A "C (gcc) ‚Äì Try It Online")
[Answer]
# [Hexagony](https://github.com/m-ender/hexagony), ~~78~~ 70 bytes
```
2"1"\.}/{}A=<\?>(<$\*}[_(A\".{}."&.'\&=/.."!=\2'%<..(@.>._.\=\{}:"<><$
```
[Try it online!](https://tio.run/##BcFBDkAwEAXQs5jQNha/WMq09BwmaSyEFVvSzNnrvet49/O5v1onGkmgvmgKLEt03EqvW3ZJCEVBBlZM8AA1QSbbMeBWRGRIkKIzceS21uEH "Hexagony ‚Äì Try It Online")
Isn't this challenge too trivial for a practical language? ;)
side length 6. I can't fit it in a side length 5 hexagon.
### Explanation
[![](https://i.stack.imgur.com/3azaW.png)](https://i.stack.imgur.com/3azaW.png)
[Answer]
# [Python](https://docs.python.org/2/), 31 bytes
```
lambda n:67-len(bin(-n))&~n>>64
```
[Try it online!](https://tio.run/##ZYu7CsJAEEX7@YpUkhSBmdnZeQj6JTaKioG4BomIjb8etxO0uofDudNrvtwKL@fNbhn318Nx35S1Wj@eSnsYStuXrlu9y3arsjwvw3hqaD3dhzI353Yo02Nuu27pCfpgTskYk3oWs@zo8O8MRInUFcmFLbkFJiBmiUrhKrWTIIJANIrgehSsC5Ix5QitL0MJ/RUZmGrrScW/aMBAgB8 "Python 2 ‚Äì Try It Online")
The expresson is the bitwise `&` of two parts:
```
67-len(bin(-n)) & ~n>>64
```
The `67-len(bin(-n))` gives the correct answer for non-negative inputs. It takes the bit length, and subtracts from 67, which is 3 more than 64 to compensate for the `-0b` prefix. The negation is a trick to adjust for `n==0` using that negating it doesn't produce a `-` sign in front.
The `& ~n>>64` makes the answer instead be `0` for negative `n`. When `n<0`, `~n>>64` equals 0 (on 64-bit integers), so and-ing with it gives `0`. When `n>=0`, the `~n>>64` evaluates to `-1`, and doing `&-1` has no effect.
---
**[Python 2](https://docs.python.org/2/), 36 bytes**
```
f=lambda n:n>0and~-f(n/2)or(n==0)*64
```
[Try it online!](https://tio.run/##ZYtLasNAEAX3fQotpYBId09PfwzyXWQUIYEzFkYheOOry7MLxKtXFPW2x77cCh/HPFzH78s0NuVUzjiW6dnPbfnk7nZvyzBg96Fy/C7r9auh03Zfy97M7Vq2n73tuqMn6IM5JWNM6lnMsqPDuzMQJVJXJBe25BaYgJglKoWr1E6CCALRKILrUbAuSMaUI7S@DCX0v8jAVFtPKv6HBgwE@AI "Python 2 ‚Äì Try It Online")
Arithmetical alternative.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 14 bytes
```
__builtin_clzl
```
Works fine on tio
# [C (gcc)](https://gcc.gnu.org/), ~~35~~ 29 bytes
```
f(long n){n=n<0?0:f(n-~n)+1;}
```
[Try it online!](https://tio.run/##S9ZNT07@/z9NIyc/L10hT7M6zzbPxsDewCpNI0@3Lk9T29C69n9uYmaehmZ1QVFmXkmahpJqioKSTpqGhaamNUIIJGIAFKn9DwA "C (gcc) ‚Äì Try It Online")
Than Dennis for 6 bytes
# [C (gcc)](https://gcc.gnu.org/) compiler flags, 29 bytes by David Foerster
```
-Df(n)=n?__builtin_clzl(n):64
```
[Try it online!](https://tio.run/##ZYzLTsMwEADv@YpVEVJMG@RX/KAtXPgLqKLUIakl46A05QDi11mWXhBw2tHs7IZqCAEvYg7p1D3B5jh3Ke6vD7fFLxdHUogxz/Dcxlx@QzsNYQXh0E5wRfz6sGPFewHQjxOcgwhbEGsam3NLtFwyCgBeJtr35eKye8yLFfRlO4@pPD@JO8bYuvhArARWXkqlrOTKuFpbWzvu8L@zqI0QxhkunJZWOeu5QiGl9kTeGU2d9kKg59wK7yUdak4Tdc1V7b2hK8u1N39FjVJQ65TR7gctShTIP0Of2uGI1X1fZrbNd02zP8U0x9yE9JbI3Rj9BQ "C (gcc) ‚Äì Try It Online")
[Answer]
# Java 8, ~~32~~ 26 bytes.
`Long::numberOfLeadingZeros`
Builtins FTW.
-6 bytes thanks to Kevin Cruijssen
[Try it online!](https://tio.run/##bZDBboMwDIbP5Sl8BGlFCQSSlHXHSZO67dDbph1SGmg6CAhCu2rqs7Mg0Wpq8cX2b3@2k704iPl@@92rsq4aA3ub@51Rhb9OhdaySZy7Stbp1KhK@89jkDhO3W0KlUJaiLaFV6E0/DpgbdRbI4x1h0ptobRVd20apfPPLxBN3npj83@7zH5cVTp/gBdtZC6bJ8hg2Q/SYqG7ciOb92wlxdbO@pBN1fa3YxJnNhtfAu3ol6DlEUbVXZ9aI0tfac8@4xY/7lQhwR1JfyfaN/ljhv2uN3X1YIWtgrZbLpS@IskkMF5Qdcav7a@YQruZL@q6OLnam2DOznR27ucY5jwIwpAGKIxZRCiNGGJwr1EgMcYxixFmJKAhoxyFgIOAcBtxFhPbRzjGwBGimPPAggRZDyRCYcR5bCmKCI/hVokgwLaZhTFhw13XjNoYMKA/ "Java (JDK) ‚Äì Try It Online")
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 25 bytes
Takes input as a BigInt literal.
```
f=x=>x<0?0:x?f(x/2n)-1:64
```
[Try it online!](https://tio.run/##fdFLbsIwEAbgfU@RZbJIMy@PZ1ApZ0GUVK2QgwBVuX3qBQjkQLzx5tP88/jd/m3Pu9PP8dKm4Ws/Tf16XH@OH7CB1bjp67Gj1LS4Upl2QzoPh/37Yfiu@7rFVM1e01RdV8FbQZ2IORKwWpAYg4Gl53QuY7pWxYKKIqopoAlFtujAN0oFRSLxDNxUclVxxBvlsgGAiO6U0wXyn@5jYdmsBODgrjk@grg@Wly24dGW7RLmcGMVS@Vq@aWNc1vORk8udrU6W9mCLevCgpXpHw "JavaScript (Node.js) ‚Äì Try It Online")
Or [**24 bytes**](https://tio.run/##fdHNbsIwDAfw@56iJ9QeutqO49iTgGdBjE6bUIoATX37LgfQkAvNJZef/PfHz@53d9mfv0/XNg@fh2nq1@N6M27HDaxWfT12lJsWP4Sn/ZAvw/Hwfhy@6r5uMVez1zRV11Xw5qgRhZAIgmjklKKC5ud0LlO@VUVHWRBFBVCZUtBkEO6UHEUitgJMhUtVNsQ7Db4BgIRmVNIZyp//x0LfLEcI0UxKfAI2ebS4bOOj9e0SlnANwpr9asNLm@bWz0ZPLnazMlvZgvV1YcHy9Ac) by returning *false* instead of \$0\$.
[Answer]
# [Python 3](https://docs.python.org/3/), 34 bytes
```
f=lambda n:-1<n<2**63and-~f(2*n|1)
```
[Try it online!](https://tio.run/##ZYtLasNAEAX3OcUsJdGC/k1/jHMYGSMscMbGeGMIuboyu0C8ekVR7/56Xm5N9n39vC5fp/NS2mGmYzvyNJks7Tz/rANP7ZvGfb09yla2VmaCOZlFnFEsqrrXwIB356BGZGFIoewSnihAzJqdMkx7p0kEieiUyf2o2Be0otRM6y9HTfsvKjD1NsQ0/tCBgQAPH6XcH1t7DuuwjeP@Cw "Python 3 ‚Äì Try It Online")
[Answer]
# [J](http://jsoftware.com/), 18 bytes
```
0{[:I.1,~(64$2)#:]
```
[Try it online!](https://tio.run/##dY5BCsJADEX3PUVQoRZqSTKZTFLoATyDuBKLuHHRpejVx9l0NsVVwvvk/TzzvEwDIIyAGd@X8TxQ/z2qHLjbj9fcNbsB2nkaWujhM8K8NM399njBDCeqmzOHkBiDWpSUoqGt2TZKayRKpKZIJpyCJcewRsQsXoCbSrkSp1rmiIncudgEy6y2iCG6a1ElFNc/PK6cqQgsqNiG1A@rvLZj/gE "J ‚Äì Try It Online")
# [J](http://jsoftware.com/), 19 bytes
```
1#.[:*/\0=(64$2)#:]
```
[Try it online!](https://tio.run/##dY4xDsIwDEX3nsKiSKUIiu04jl2pJwEmRIVYGDpz9pClWSomW@/L7/ud52UaAGEEzNQO1/F4ueF0UNlz34733De7Abp5Gjo4wXeEeWma5@P1gRnOVDdnDiExBrUoKUVDW7NtlNZIlEhNkUw4BUuOYY2IWbwAN5VyJU61zBETuXOxCZZZbRFDdNeiSiiuf3hcOVMRWFCxDakfVnltx/wD "J ‚Äì Try It Online")
## Explanation:
```
                #:  - convert 
                  ] - the input to
          (64$2)    - 64 binary digits
         =          - check if each digit equals 
        0           - zero
   [:*/\            - find the running product
1#.                 - sum
```
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 18 bytes
*-2 bytes thanks to Jo King*
```
64-(*%2**64*2).msb
```
[Try it online!](https://tio.run/##rdNRb4IwEAfw936Ke9kEFL22x7WNWeb3mD7opomJzkWezLLPzi4bEzJIMOC9FNLml7s/5WN7PnBxvMDjDp6gYEqj5MEkCVNi4ukx3xRztTudITrs37d5DJ8KQE4v1nJ6@no6bqLZMn1evo1n8VzJXr6@wC5arF9wFU9GsM9hNBnLq16pryLV0Cz8e9ADS6XBGGudQcs@I@cyj77G47BSTd2Jeh1jaPfEWrNn1J6Ms94FtADmyg/0lTaGgqDBM0n3FLS0bisef/LpzQdEp0MwkgyhrGXkFV9Wv6@gKEObhcCSjEMKXF6YBt/P/89nv7xp8r0CUkZLKt4y@dq9t218W3WNVPGuztsbeezsvuWnBb61@67ZlG7l7V141ApbeboPj98 "Perl 6 ‚Äì Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 22 bytes
```
->n{/[^0]/=~"%064b"%n}
```
[Try it online!](https://tio.run/##bY69CsJAEIR7n0ICKUP27/aniC8SYpEiZRDBQkRf/Ty8q9RqmB3mm73e1nvepjyc9sc4n2EZp1fXg8ra9fszX47bPOBy@GgQMRsBqycxSw5ek9/AaiCKqK6ALmTsFsA1QCKJYsNVSkMC20gAGEZQ4QgUbZwEnCK0QAwk9O811SthqTqr@JdvPzVk24MlvwE "Ruby ‚Äì Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~10~~ 9 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
¬∑bg65Œ±sd*
```
I/O are both integers
[Try it online](https://tio.run/##yy9OTMpM/f//0PakdDPTcxuLU7T@/zcxMzQ0szAzMLQwMTI3tjC3NDAGAA) or [verify all test cases](https://tio.run/##ZYu7CQJREEXzqWLZUFyY35tPtImNuChiZLAgLBhbgJ0YmVuARdjI82WCRvdwOPc0b6fjvl7Oy9h37@ut68dlU5@P6WDldZ93q7quA8GQzCLOKBZF3UtgwL9zUCOyMKRQdglPFCBmzUYZpq3TJIJEdMrkdlRsC1pQSqa1l6Om/YoCTK0NMY0vOjAQ4Ac).
**Explanation:**
```
¬∑         # Double the (implicit) input
          #  i.e. -1 ‚Üí -2
          #  i.e. 4503599627370496 ‚Üí 9007199254740992
 b        # Convert it to binary
          #  i.e. -2 ‚Üí "√ø0"
          #  i.e. 9007199254740992 ‚Üí 100000000000000000000000000000000000000000000000000000
  g       # Take its length
          #  i.e. "√ø0" ‚Üí 2
          #  i.e. 100000000000000000000000000000000000000000000000000000 ‚Üí 54
   65Œ±    # Take the absolute different with 65
          #  i.e. 65 and 2 ‚Üí 63
          #  i.e. 65 and 54 ‚Üí 11
      s   # Swap to take the (implicit) input again
       d  # Check if it's non-negative (>= 0): 0 if negative; 1 if 0 or positive
          #  i.e. -1 ‚Üí 0
          #  i.e. 4503599627370496 ‚Üí 1
        * # Multiply them (and output implicitly)
          #  i.e. 63 and 0 ‚Üí 0
          #  i.e. 11 and 1 ‚Üí 11
```
[Answer]
# [Haskell](https://www.haskell.org/), 56 bytes
Thanks [xnor](https://codegolf.stackexchange.com/users/20260/xnor) for spotting a mistake!
```
f n|n<0=0|1>0=sum.fst.span(>0)$mapM(pure[1,0])[1..64]!!n
```
Might allocate quite a lot of memory, [try it online!](https://tio.run/##JcqxDoMgFIXhvU9xTTpgouQCKjQpvkGfgDAwaGoqhIhuvju1dPnOcP63S59pXXOeIZzhiRpPNqJOh6dz2mmKLpAR67t38UXisU2GNWhrwygdOltVIXu3BNDwC4DEbQk7nesbgIGWXdNA@@BcCMlRDKrvpOwVqnIMRV78p3hp8xc "Haskell ‚Äì Try It Online")
Maybe you want to test it with a smaller constant: [Try 8-bit!](https://tio.run/##y0gszk7Nyfn/P00hrybPxsDWoMbQzsC2uDRXL624RK@4IDFPw85AUyU3scBXo6C0KDXaUMcgVjPaUE/PIlZRMe9/bmJmnoKtAkheQaOgKDOvRC9Nk0tBIVpB1xhI6SjoGoIpAzAJYRuBSTOIiJE5kI79DwA "Haskell ‚Äì Try It Online")
## Explanation
Instead of using `mapM(pure[0,1])[1..64]` to convert the input to binary, we'll use `mapM(pure[1,0])[1..64]` which essentially generates the inverted strings \$\lbrace0,1\rbrace^{64}\$ in lexicographic order. So we can just sum the \$1\$s-prefix by using `sum.fst.span(>0)`.
[Answer]
# Powershell, 51 bytes
```
param([long]$n)for(;$n-shl$i++-gt0){}($i,65)[!$n]-1
```
Test script:
```
$f = {
param([long]$n)for(;$n-shl$i++-gt0){}($i,65)[!$n]-1
}
@(
    ,(-1                   ,0 )
    ,(-9223372036854775808 ,0 )
    ,(9223372036854775807  ,1 )
    ,(4611686018427387903  ,2 )
    ,(1224979098644774911  ,3 )
    ,(9007199254740992     ,10)
    ,(4503599627370496     ,11)
    ,(4503599627370495     ,12)
    ,(2147483648           ,32)
    ,(2147483647           ,33)
    ,(2                    ,62)
    ,(1                    ,63)
    ,(0                    ,64)
) | % {
    $n,$expected = $_
    $result = &$f $n
    "$($result-eq$expected): $result"
}
```
Output:
```
True: 0
True: 0
True: 1
True: 2
True: 3
True: 10
True: 11
True: 12
True: 32
True: 33
True: 62
True: 63
True: 64
```
[Answer]
# Java 8, 38 bytes
```
int f(long n){return n<0?0:f(n-~n)+1;}
```
Input as `long` (64-bit integer), output as `int` (32-bit integer).
Port of [*@l4m2*'s C (gcc) answer](https://codegolf.stackexchange.com/a/177291/52210).
[Try it online.](https://tio.run/##fZFNTsMwEIX3PcWoK0dRqvFP/EORuACsukQsQptULqlTJU4lVIUlB@CIXCSYEAksECtr5vl9Hr85FOciO@yexm1ddB3cFdZdFgCdL7zdwmidh4rUjduDSy5t6fvWgbvGG7yqiMteXJLS9TAGx6l/rINjNp4bu4NjgJGNb63b3z9AkXyCAXzZeZLR22T9ozSMca4YcqlzoVSuUUcXfusq0oWkVGqJVAumuFYGeaRTxoQJXaOlCH5haDyAQVTUGBbgAsMZw3PkuTEykBUKI/8T80hkNPA0l0L/3Y4/Eb8aD4hf1bD4Xs6U8SRO@7FzvpvnzpfHVdP71SlE72tHbLqE99c3WKYVsckMGsYP)
**Explanation:**
```
 int f(long n){       // Recursive method with long parameter and integer return-type
   return n<0?        //  If the input is negative:
           0          //   Return 0
          :           //  Else:
           f(n-~n)    //   Do a recursive call with n+n+1
                  +1  //   And add 1
```
---
EDIT: Can be **26 bytes** by using the builtin `Long::numberOfLeadingZeros` as displayed in [*@lukeg*'s Java 8 answer](https://codegolf.stackexchange.com/a/177304/52210).
[Answer]
# APL+WIN, 34 bytes
```
+/√ó\0=(0>n),(63‚ç¥2)‚ä§((2*63)√ó√ón)+n‚Üê‚éï
```
Explanation:
```
n‚Üê‚éï Prompts for input of number as integer
((2*63)√ó√ón) If n is negative add 2 to power 63
(63‚ç¥2)‚ä§ Convert to 63 bit binary
(0>n), Concatinate 1 to front of binary vector if n negative, 0 if positive
+/√ó\0= Identify zeros, isolate first contiguous group and sum if first element is zero
```
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 42 bytes
```
x=>x!=0?64-Convert.ToString(x,2).Length:64
```
[Try it online!](https://tio.run/##ZVA9T8MwFJzxr3C3RHIif8UfLSkDElO3IjEghsoyqaXiSLapghC/PTgNAQRveffu3t1wJlYmuvHu1ZvrU@875HzaQgNbOA7tdli1@Ebw6rb3ZxtSfd/vU3C@KwZEy3pnfZeOa8HHDQCT@fEJJhuTDTH73yuCQKUpZUxSzIRquJSNwgrBrwH/RQkXFXBBiFACE8WpZEpqzCAChFKuM9ZK8GzhmhD4KxBjSbSmOY3jvCcSTVkNZo3WIgdJzLWY@b90s7xTkv2KCa7mXPTDyPmEi0C@Ef7ILTz3wR7MsTgfwqWKCJ1fOinB1f4to5c61xn7k60fgkt257wtTHH5LsvN@Ak "C# (Visual C# Interactive Compiler) ‚Äì Try It Online")
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 31 bytes
```
int c(long x)=>x<0?0:c(x-~x)+1;
```
Even shorter, based off of [@l4m2's C (gcc) answer.](https://codegolf.stackexchange.com/a/177291/52210)
Never knew that you could declare functions like that, thanks @Dana!
[Try it online!](https://tio.run/##ZZA/T8QwDMVn8ik8tqI92UmaP1cOBlY2BgbEcIoCRLpLpaZCRQi@ekmvFBB48fN79m@wS7VLYZpCHMAVhy4@wVjuLscLvMKtK8b6YyzPqZ0Ym7P7Bxh8GnyfYAdvNVWstpwLoTkKZRqpdWPQVPBV7H@oYU2ZVETKKCQjuRZGWxRQMeJc2qytUTKfSEsEv4CImqzlmSYx99msZlaDorFWZZBGadXi/7WbdZ1TvjdCSbNwqx9HLyOsAX0rfG8Ze@x6v3fPxcu@P70iQYjrT0p2dvua1XFz3cXUHfzmrg@DvwnRF644bZdlO30C "C# (Visual C# Interactive Compiler) ‚Äì Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~¬†10¬†~~ 9 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
-1 thanks to a neat trick by Erik the Outgolfer (is-non-negative is now simply `A∆ë`)
```
·∏§BL65_√óA∆ë
```
A monadic Link accepting an integer (within range) which yields an integer.
**[Try it online!](https://tio.run/##y0rNyan8///hjiVOPmam8YenOx6b@P//fxNTA2NTS0szI3NjcwMTSzMA "Jelly ‚Äì Try It Online")** Or see the [test-suite](https://tio.run/##ddA7TgNBDAbg3qeIlHYi@TV@lEmdGyBERYNyAVoaaiouQJkDpF8p90guMhmxQgvLZhpL88m/bL88Hw6vrV1OX7u91afhc3v@aMP79e3Y2gNsqKwW3nqFsElmEWcUi6ruNTDKSP/Fy3cXgRqRhSGFskt4oozEQMya/SPDtHdpEo0kkIhOmdzTFHstP2MQglaUmmk9zlHTJqO51ckYmHpYiGmUv6vJL/O5CfDiRbpZX@GuCeBdU3i8AQ "Jelly ‚Äì Try It Online").
---
The 10 was `·∏§BL65_…ì>-√ó`
Here is another 10 byte solution, which I like since it says it is "BOSS"...
```
Bo·π†S¬ª-~%65
```
[Test-suite here](https://tio.run/##ddA9akJBEAfwfk4hhHT7YL52PtpcwVIsbUSwTpMiTa6RA@QCwS45SbzIuuQh6tO3zcD@mD8zs93sdq@tvez/vj@XP4fh7dlq@/04vn@1toKByuLBe1ogDMks4oxiUdW9BkYZ6V68/HcRqBFZGFIou4QnykgMxKzZPzJMe5cm0UgCieiUyT1NsddyHoMQtKLUTOtxjpp2MZpavRgDUw8LMY1yu5pcmU9NgB9epJv1FWZNAGdNYX0C "Jelly ‚Äì Try It Online")
...`Bo·π†S63r0¬§i`, `Bo·π†S63≈ª·πö¬§i`, or `Bo·π†S64·∏∂·πö¬§i` would also work.
---
Another 10 byter (from Dennis) is `√¶¬ª64·∏∂·πö¬§√Ñƒã0` (again `√¶¬ª63r0¬§√Ñƒã0` and `√¶¬ª63≈ª·πö¬§√Ñƒã0` will also work)
[Answer]
# [Perl 5](https://www.perl.org/), 37 bytes
```
sub{sprintf("%064b",@_)=~/^0*/;$+[0]}
```
[Try it online!](https://tio.run/##rZPrTsJAEIX/71NMNouhUmH20r1Yq7yHFyJSCJFLpSWRGH11XAoKkSYY4PxpMzv55szpNktno2g5XrB@sszn3Y88mw0nRb9Oa6hVl4btTpB8tZ7wshWzxj0@fi7j8QLaRZoXyfg5g/s8Gw2L1kPeaD2GN7cx6U9n9fI4@CDgNV7U2TBkaZC0WSfelIANkgvW9yfBurSeCpQ26yyF9M033FF6TSfTAmjQpNNX3zScZPPiGmoiyiGB0iBA@p6lL0XaW9V7AINp2dF7mNBwNXc1OmSDmHwurzjsC39e@IkiV04IKY1AqW2kjIks2h08niayTzee@rvGqe6V5lxbjdwqYaQ1DiWA@MWfyCdcCOU81FmtvHvluLcut3gs8zka7xANd074ZBT65ybyLX6j474CURHKyDntkzGonN5cmD38cfy/@GiNF/v4owIigvtUrNTK7tx7WYWv0qGVtnizi5f/xONB9xU/Lej/uj@0G@GVeHkWPHKClXh1Hjx@Aw "Perl 5 ‚Äì Try It Online")
Or this 46 bytes if the "stringification" is not allowed: sub z
```
sub{my$i=0;$_[0]>>64-$_?last:$i++for 1..64;$i}
```
[Answer]
# Swift (on a 64-bit platform), 41 bytes
Declares a closure called `f` which accepts and returns an `Int`. This solution only works correctly 64-bit platforms, where `Int` is `typealias`ed to `Int64`. (On a 32-bit platform, `Int64` can be used explicitly for the closure‚Äôs parameter type, adding 2 bytes.)
```
let f:(Int)->Int={$0.leadingZeroBitCount}
```
In Swift, even the fundamental integer type is an ordinary object declared in the standard library. This means `Int` can have methods and properties, such as [`leadingZeroBitCount`](https://developer.apple.com/documentation/swift/int/2884587-leadingzerobitcount) (which is required on all types conforming to the standard library‚Äôs [`FixedWidthInteger`](https://developer.apple.com/documentation/swift/fixedwidthinteger) protocol).
[Answer]
# [Haskell](https://www.haskell.org/), 24 bytes
```
f n|n<0=0
f n=1+f(2*n+1)
```
[Try it online!](https://tio.run/##ZY2xDsIwDET3foXHllJkO2niVOQDGPgCxJCBioo2qqAj/x6idGQ5n9@ddM/weT3mOaUR4jee0WOVnad2rPkQW2rSEqYIHpawXqFe31PcTmNTAdygo3yO0DlmpSyjMtJra3tBKcE/t4VrQ2TEIIlmq8Q6VIUTs3b5c2J07mtH@4ApynunKA7DJW7Z3tMP "Haskell ‚Äì Try It Online")
This is basically the same as Kevin Cruijssen's Java solution, but I found it independently.
The argument should have type `Int` for a 64-bit build, or `Int64` for anything.
## Explanation
If the argument is negative, the result is immediately 0. Otherwise, we shift left, *filling in with ones*, until we reach a negative number. That filling lets us avoid a special case for 0.
Just for reference, here's the obvious/efficient way:
# 34 bytes
```
import Data.Bits
countLeadingZeros
```
[Answer]
# [Clean](https://github.com/Ourous/curated-clean-linux), 103 bytes
Uses the same *"builtin"* as ceilingcat's answer.
```
f::!Int->Int
f _=code {
instruction 243
instruction 72
instruction 15
instruction 189
instruction 192
}
```
[Try it online!](https://tio.run/##S85JTcz7n5ufUpqTqpCbmJn3P83KStEzr0TXDkhwpSnE2ybnp6QqVHNl5hWXFJUml2Tm5ykYmRij8M2NULiGpqhcC0tUvqURV@3/4JLEohIFW4U0BYP/AA "Clean ‚Äì Try It Online")
# [Clean](https://github.com/Ourous/curated-clean-linux), 58 bytes
```
import StdEnv
$0=64
$i=until(\e=(2^63>>e)bitand i<>0)inc 0
```
[Try it online!](https://tio.run/##S85JTcz7n5ufUpqTqpCbmJn3PzO3IL@oRCG4JMU1r4xLxcDWzIRLJdO2NK8kM0cjJtVWwyjOzNjOLlUzKbMkMS9FIdPGzkAzMy9ZweB/cEkiUKetgoqCgQIc/P@XnJaTmF78X9fT579LZV5ibmZyMQA "Clean ‚Äì Try It Online")
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 10 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
√Æn¬ª‚ïß3(‚àû‚îº‚å†g
```
[Run and debug it](https://staxlang.xyz/#p=8c6eafcf3328ecc5f467&i=-1%0A-9223372036854775808%0A9223372036854775807%0A4611686018427387903%0A1224979098644774911%0A9007199254740992%0A4503599627370496%0A4503599627370495%0A2147483648%0A2147483647%0A2%0A1%0A0&a=1&m=2)
It's a port of Kevin's 05AB1E solution.
[Answer]
# [Perl 5](https://www.perl.org/) `-p`, 42 bytes
```
1while$_>0&&2**++$a-1<$_;$_=0|$_>=0&&64-$a
```
[Try it online!](https://tio.run/##rdPNaoQwEAfwe54i0LCHXSwz@Q7WvkGfQTxYarEqftAe@uxNQ7tdpQouunOJGPgx83ds8rZU3uP7S1HmLH2Ew4Efj6cTyyJ8YGnM0gQ@w/skXGgZsczHLEsgpnf5R9H1HX0dup4@1y19G8q@aMqc9m2Rd7SoaF3ltB0qHyGdF/w94M4ikeNcCMNBaKukMcqCnfCwr8hcN0G9jLG3e6kRtdWAVnIjrHEgKOUXfqdPkHPpAuqslqF76TC0LkYefvLZzDsAg87xkIyEcJ4jH/lzbfsKRCoQyjkdkjEgnT4vzIzf5v/n1S/P5/ymgAjHkIoVWtrJ3oslfqnWRhp5M@XFlTysLiYRhC/8uFRfO8HafAQXeXETHpDAIi9vw8NX3fRFXXU@elL3YRofNeU3 "Perl 5 ‚Äì Try It Online")
Longer than a bitstring based solution, but a decent math based solution.
[Answer]
# APL(NARS), 15 chars, 30 bytes
```
{¬Ø1+1‚ç≥‚ç®‚çµ‚ä§‚ç®64‚ç¥2}
```
test for few numbers for see how to use:
```
  f‚Üê{¬Ø1+1‚ç≥‚ç®‚çµ‚ä§‚ç®64‚ç¥2}
  f ¬Ø9223372036854775808
0
  f 9223372036854775807
1
```
[Answer]
# Rust, 18 bytes
```
i64::leading_zeros
```
[Try it online!](https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=71da8c48aa4f1edd0fb85db20d7281d4)
[Answer]
# PHP, ~~50~~ 46 bytes
```
for(;0<$n=&$argn;$n>>=1)$i++;echo$n<0?0:64-$i;
```
Run as pipe with `-R` or [try it online](http://sandbox.onlinephpfunctions.com/code/7d03c08accfe0eaa3e19c42efec9c7bca8b40ae6),
`<?=$argn<0?0:0|64-log($argn+1,2);` has rounding issues; so I took the long way.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 41 bytes
The formula for positive numbers is just `63-Floor@Log2@#&`. Replacement rules are used for the special cases of zero and negative input.
The input need not be a 64-bit signed integer. This will effectively take the floor of the input to turn it into an integer. If you input a number outside of the normal bounds for a 64-bit integer, it will tell return a negative number indicating how many more bits would be needed to store this integer.
```
63-Floor@Log2[#/.{_?(#<0&):>2^63,0:>.5}]&
```
[Try it online!](https://tio.run/##ZY9NawJBEER/jCARerW/pnvaROMppxxyFyOLrImgWXDnJv72zZwSSE5VPOod6tKWz@7SltOhHUs3lEM7dMPq1hA0wSzijGI5qXvKmOE/c1AjsmxIWdkle6AAMWvUFtm07jSIIBCdIriKijVBE0qKsGo5athfkICpbrOY5t/qwECA98fjajRpXs59f9289h@8nSzmt/3zw@QJp7Plmt9NAJfrebrvpuPb9fRVtsfF5ufkbvwG "Wolfram Language (Mathematica) ‚Äì Try It Online")
@LegionMammal978's solution is quite a bit shorter at 28 bytes. The input must be an integer. Per the documentation: "`BitLength[n]` is effectively an efficient version of `Floor[Log[2,n]]+1`. " It automatically handles the case of zero correctly reporting `0` rather than `-‚àû`.
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 28 bytes
```
Boole[#>=0](64-BitLength@#)&
```
[Try it online!](https://tio.run/##ZY@7asNAEEU/xhAcGOGZ2dl5YBSM6xTujQth1pbAD4i2C/l2ZasEkupeDvcU9z7UsdyHOp2HpZa5noe5zP1nR9AFc0rGmNSzmGVHh//MQJRIXZFc2JJbYAJilmgtXKXtJIggEI0iuImCLUEyphyhzTKU0L8gA1PbelLx32rAQIBf20u/7J/PWzmu3no8rVW6/VTfy@Nax93q9WU5fEyPerxsdj@/Tss3 "Wolfram Language (Mathematica) ‚Äì Try It Online")
[Answer]
bitNumber - math.ceil (math.log(number) / math.log(2))
e.g
64 bit 
NUMBER : 9223372036854775807
math.ceil (math.log(9223372036854775807) / math.log(2)) 
ANS: 63 
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 12 bytes
```
+/&\~(64#2)\
```
[Try it online!](https://ngn.codeberg.page/k#eJxljstqAlEMhvfzFEJFlCLN7eQy51E0oJuB0kJBXCjiPHvPmZ24Cv+X5Eum8fNrc5y3Kh+0Ow7DdXysD/f5Mk6rWz39/dTtaTp//9ZbvdfLLp/D9bDHhF6CiNkIWL2IWXHwpfHOLbFxUUR1BXQhY7cATmociSRaCldp8xKIyd0DYBhBTSLQamK3SwEuEdoUBhKaiO+0JHYzYVt1VvHkl2zJ/QKlLg+k9gSp8g/x20FX)
`(64#2)\` encode the argument as 64 bits
`~` bitwise not
`&\` cumulative boolean and
`+/` sum
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 15 bytes
```
Ôº©‚Åª‚Å∂‚Å¥Ôº¨‚Ü®Ôπ™ÔºÆÔº∏¬≤¬¶‚Å∂‚Å¥¬¶¬≤
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEwzczr7RYw8xER8EnNS@9JEPDKbE4VcM3P6U0J1/DM6@gtMSvNDcptUhDU0chIL8cyDDSUTAz0QRyjTTBwPr/f4P/umU5AA "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Explanation:
```
    Ôº¨           Length of
       ÔºÆ        Input as a number
      Ôπ™         Modulo
         ¬≤      Literal 2
        Ôº∏       To the power
           ‚Å∂‚Å¥   Literal 64
     ‚Ü®          Converted to base
              ¬≤ Literal 2
 ‚Åª              Subtracted from
  ‚Å∂‚Å¥            Literal 64
Ôº©               Cast to string
                Implicitly print
```
The `¬¶`s serve to separate adjacent integer literals. Conveniently, Charcoal's arbitrary numeric base conversion converts `0` into an empty list, however for negative numbers it simply inverts the sign of each digit, so the number is converted to the equivalent unsigned 64-bit integer first.
]