diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 3c92450..4939edb 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -1584,6 +1584,8 @@ function _comment_per_page() {
  * 110, 111, ... , 1zy, 1zz,
  * 2100, 2101, ..., 2zzy, 2zzz,
  * 31000, 31001, ...
+ *
+ * @deprecated Use \Drupal\comment\CommentInterface::intToAlphadecimal() instead.
  */
 function comment_int_to_alphadecimal($i = 0) {
   $num = base_convert((int) $i, 10, 36);
@@ -1595,7 +1597,7 @@ function comment_int_to_alphadecimal($i = 0) {
 /**
  * Decodes a sorting code back to an integer.
  *
- * @see comment_int_to_alphadecimal()
+ * @deprecated Use \Drupal\comment\CommentInterface::alphadecimalToInt() instead.
  */
 function comment_alphadecimal_to_int($c = '00') {
   return base_convert(substr($c, 1), 36, 10);
diff --git a/core/modules/comment/lib/Drupal/comment/CommentInterface.php b/core/modules/comment/lib/Drupal/comment/CommentInterface.php
index 28ec9fb..b8108b6 100644
--- a/core/modules/comment/lib/Drupal/comment/CommentInterface.php
+++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.php
@@ -35,4 +35,28 @@
    */
   public function permalink();
 
+  /**
+   * Generates a sorting code.
+   *
+   * Consists of a leading character indicating length, followed by N digits
+   * with a numerical value in base 36 (alphadecimal). These codes can be sorted
+   * as strings without altering numerical order.
+   *
+   * It goes:
+   * 00, 01, 02, ..., 0y, 0z,
+   * 110, 111, ... , 1zy, 1zz,
+   * 2100, 2101, ..., 2zzy, 2zzz,
+   * 31000, 31001, ...
+   *
+   * @see \Drupal\comment\CommentInterface::alphadecimalToInt
+   */
+  public static function intToAlphadecimal($i = 0);
+
+  /**
+   * Decodes a sorting code back to an integer.
+   *
+   * @see \Drupal\comment\CommentInterface::intToAlphadecimal
+   */
+  function alphadecimalToInt($c = '00');
+
 }
diff --git a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
index d2c79bd..6f4abcf 100644
--- a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
+++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
@@ -242,7 +242,7 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
           $max = rtrim($max, '/');
           // We need to get the value at the correct depth.
           $parts = explode('.', $max);
-          $n = comment_alphadecimal_to_int($parts[0]);
+          $n = static::alphadecimalToInt($parts[0]);
           $prefix = '';
         }
         else {
@@ -269,14 +269,14 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
             // Get the value at the correct depth.
             $parts = explode('.', $max);
             $parent_depth = count(explode('.', $parent->thread->value));
-            $n = comment_alphadecimal_to_int($parts[$parent_depth]);
+            $n = static::alphadecimalToInt($parts[$parent_depth]);
           }
         }
         // Finally, build the thread field for this new comment. To avoid
         // race conditions, get a lock on the thread. If aother process already
         // has the lock, just move to the next integer.
         do {
-          $thread = $prefix . comment_int_to_alphadecimal(++$n) . '/';
+          $thread = $prefix . static::intToAlphadecimal(++$n) . '/';
         } while (!lock()->acquire("comment:{$this->entity_id->value}:$thread"));
         $this->threadLock = $thread;
       }
@@ -462,4 +462,21 @@ public static function preCreate(EntityStorageControllerInterface $storage_contr
     }
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public static function intToAlphadecimal($i = 0) {
+    $num = base_convert((int) $i, 10, 36);
+    $length = strlen($num);
+
+    return chr($length + ord('0') - 1) . $num;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  function alphadecimalToInt($c = '00') {
+    return base_convert(substr($c, 1), 36, 10);
+  }
+
 }
