 core/includes/bootstrap.inc                      |   11 ++-
 core/includes/common.inc                         |  108 ++++++++++++----------
 core/includes/file.inc                           |   14 ++--
 core/includes/gettext.inc                        |    4 +-
 core/modules/color/color.module                  |    4 +-
 core/modules/file/file.field.inc                 |   20 ++--
 core/modules/file/file.module                    |    6 +-
 core/modules/file/tests/file.test                |   28 +++---
 core/modules/image/image.field.inc               |    2 +-
 core/modules/image/image.test                    |    4 +-
 core/modules/simpletest/drupal_web_test_case.php |    2 +-
 core/modules/simpletest/simpletest.install       |    2 +-
 core/modules/simpletest/tests/common.test        |   91 ++++++++++++------
 core/modules/simpletest/tests/file.test          |    4 +-
 core/modules/simpletest/tests/xmlrpc.test        |    2 +-
 core/modules/simpletest/tests/xmlrpc_test.module |    6 +-
 core/modules/system/system.install               |    2 +-
 core/modules/system/system.tokens.inc            |    2 +-
 core/modules/user/user.admin.inc                 |    2 +-
 core/modules/user/user.module                    |    2 +-
 core/modules/user/user.test                      |    6 +-
 21 files changed, 184 insertions(+), 138 deletions(-)

diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 838c5dc..742bcc1 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -157,9 +157,16 @@ const DRUPAL_AUTHENTICATED_RID = 2;
 /**
  * The number of bytes in a kilobyte.
  *
- * For more information, visit http://en.wikipedia.org/wiki/Kilobyte.
+ * See http://en.wikipedia.org/wiki/Kilobyte for more information.
  */
-const DRUPAL_KILOBYTE = 1024;
+const DRUPAL_KILOBYTE = 1000;
+
+/**
+ * The number of bytes in a kibibyte.
+ *
+ * See http://en.wikipedia.org/wiki/Kibibyte for more information.
+ */
+const DRUPAL_KIBIBYTE = 1024;
 
 /**
  * System language (only applicable to UI).
diff --git a/core/includes/common.inc b/core/includes/common.inc
index a4fcf51..fa7b850 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -897,7 +897,7 @@ function drupal_http_request($url, array $options = array()) {
       break;
     }
     stream_set_timeout($fp, floor($timeout), floor(1000000 * fmod($timeout, 1)));
-    $chunk = fread($fp, 1024);
+    $chunk = fread($fp, DRUPAL_KIBIBYTE);
     $response .= $chunk;
     $info = stream_get_meta_data($fp);
     $alive = !$info['eof'] && !$info['timed_out'] && $chunk;
@@ -1742,65 +1742,79 @@ function format_plural($count, $singular, $plural, array $args = array(), array
 }
 
 /**
- * Parses a given byte count.
+ * Parses a human-readable representation of a byte count.
  *
- * @param $size
- *   A size expressed as a number of bytes with optional SI or IEC binary unit
- *   prefix (e.g. 2, 3K, 5MB, 10G, 6GiB, 8 bytes, 9mbytes).
+ * See http://en.wikipedia.org/wiki/Binary_prefix for more information.
+ *
+ * @param $count
+ *   A byte count expressed as a numeric quantity, optionally followed by a
+ *   unit:
+ *    - SI (powers of 1000), e.g. 7.4kB, 8 MB, 42.9 megabytes, 9 G, 1terabyte.
+ *    - IEC (powers of 1024), e.g. 9 Kibibytes, 0.3 MiB, 40gibibytes.
+ * @param $force_iec
+ *   Override the unit type detection to be IEC.
  *
  * @return
- *   An integer representation of the size in bytes.
+ *   An integer representation of the byte count.
+ *
+ * @see format_byte_count()
  */
-function parse_size($size) {
-  $unit = preg_replace('/[^bkmgtpezy]/i', '', $size); // Remove the non-unit characters from the size.
-  $size = preg_replace('/[^0-9\.]/', '', $size); // Remove the non-numeric characters from the size.
-  if ($unit) {
-    // Find the position of the unit in the ordered string which is the power of magnitude to multiply a kilobyte by.
-    return round($size * pow(DRUPAL_KILOBYTE, stripos('bkmgtpezy', $unit[0])));
-  }
-  else {
-    return round($size);
+function parse_byte_count($count, $force_iec = FALSE) {
+  // Break up the count into quantity and unit.
+  preg_match('/([0-9.]+)[ ]*([a-z]*)/', strtolower($count), $matches);
+
+  $quantity = $matches[1];
+  $unit = $matches[2];
+  $unit_length = strlen($unit);
+
+  if ($unit_length > 0) {
+    // Determine if the unit is SI or IEC. The second letter of an abbreviated
+    // IEC unit is always 'i', e.g. Mi or MiB. The forth letter of an
+    // unabbreviated IEC unit is always 'i', e.g. mebibyte.
+    if ((($unit_length == 2 || $unit_length == 3) && $unit[1] == 'i') ||
+      ($unit_length >= 4 && $unit[3] == 'i') || $force_iec)
+    {
+      $base = DRUPAL_KIBIBYTE;
+    }
+    else {
+      $base = DRUPAL_KILOBYTE;
+    }
+
+    // Multiply the quantity by the quantity of the unit. The quantity of the
+    // unit is calculated by determining its order of magnitude and raising the
+    // base of the unit to this power.
+    $quantity *= pow($base, strpos('bkmgtpezy', $unit[0]));
   }
+
+  // Make sure an integer is returned.
+  return floor($quantity);
 }
 
 /**
- * Generates a string representation for the given byte count.
+ * Formats a byte count into a human-readable representation.
  *
- * @param $size
- *   A size in bytes.
- * @param $langcode
- *   Optional language code to translate to a language other than what is used
- *   to display the page.
+ * See http://en.wikipedia.org/wiki/Kilobyte for more information.
+ *
+ * @param $count
+ *   An integer byte count.
  *
  * @return
- *   A translated string representation of the size.
+ *   A human readable representation of the byte count.
+ *
+ * @see parse_byte_count()
  */
-function format_size($size, $langcode = NULL) {
-  if ($size < DRUPAL_KILOBYTE) {
-    return format_plural($size, '1 byte', '@count bytes', array(), array('langcode' => $langcode));
-  }
-  else {
-    $size = $size / DRUPAL_KILOBYTE; // Convert bytes to kilobytes.
-    $units = array(
-      t('@size KB', array(), array('langcode' => $langcode)),
-      t('@size MB', array(), array('langcode' => $langcode)),
-      t('@size GB', array(), array('langcode' => $langcode)),
-      t('@size TB', array(), array('langcode' => $langcode)),
-      t('@size PB', array(), array('langcode' => $langcode)),
-      t('@size EB', array(), array('langcode' => $langcode)),
-      t('@size ZB', array(), array('langcode' => $langcode)),
-      t('@size YB', array(), array('langcode' => $langcode)),
-    );
-    foreach ($units as $unit) {
-      if (round($size, 2) >= DRUPAL_KILOBYTE) {
-        $size = $size / DRUPAL_KILOBYTE;
-      }
-      else {
-        break;
-      }
+function format_byte_count($count) {
+  $units = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
+
+  foreach ($units as $unit) {
+    if ($count < DRUPAL_KILOBYTE) {
+      break;
     }
-    return str_replace('@size', round($size, 2), $unit);
+
+    $count /= DRUPAL_KILOBYTE;
   }
+
+  return round($count, 2) . ' ' . $unit;
 }
 
 /**
diff --git a/core/includes/file.inc b/core/includes/file.inc
index 05bf6c1..c803784 100644
--- a/core/includes/file.inc
+++ b/core/includes/file.inc
@@ -1432,7 +1432,7 @@ function file_save_upload($source, $validators = array(), $destination = FALSE,
   switch ($_FILES['files']['error'][$source]) {
     case UPLOAD_ERR_INI_SIZE:
     case UPLOAD_ERR_FORM_SIZE:
-      drupal_set_message(t('The file %file could not be saved because it exceeds %maxsize, the maximum allowed size for uploads.', array('%file' => $_FILES['files']['name'][$source], '%maxsize' => format_size(file_upload_max_size()))), 'error');
+      drupal_set_message(t('The file %file could not be saved because it exceeds %maxsize, the maximum allowed size for uploads.', array('%file' => $_FILES['files']['name'][$source], '%maxsize' => format_byte_count(file_upload_max_size()))), 'error');
       return FALSE;
 
     case UPLOAD_ERR_PARTIAL:
@@ -1724,12 +1724,12 @@ function file_validate_size(stdClass $file, $file_limit = 0, $user_limit = 0) {
   // Bypass validation for uid  = 1.
   if ($user->uid != 1) {
     if ($file_limit && $file->filesize > $file_limit) {
-      $errors[] = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size($file->filesize), '%maxsize' => format_size($file_limit)));
+      $errors[] = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_byte_count($file->filesize), '%maxsize' => format_byte_count($file_limit)));
     }
 
     // Save a query by only calling file_space_used() when a limit is provided.
     if ($user_limit && (file_space_used($user->uid) + $file->filesize) > $user_limit) {
-      $errors[] = t('The file is %filesize which would exceed your disk quota of %quota.', array('%filesize' => format_size($file->filesize), '%quota' => format_size($user_limit)));
+      $errors[] = t('The file is %filesize which would exceed your disk quota of %quota.', array('%filesize' => format_byte_count($file->filesize), '%quota' => format_byte_count($user_limit)));
     }
   }
   return $errors;
@@ -1936,10 +1936,10 @@ function file_transfer($uri, $headers) {
   }
   drupal_send_headers();
   $scheme = file_uri_scheme($uri);
-  // Transfer file in 1024 byte chunks to save memory usage.
+  // Transfer file in kibibyte chunks to save memory usage.
   if ($scheme && file_stream_wrapper_valid_scheme($scheme) && $fd = fopen($uri, 'rb')) {
     while (!feof($fd)) {
-      print fread($fd, 1024);
+      print fread($fd, DRUPAL_KIBIBYTE);
     }
     fclose($fd);
   }
@@ -2080,11 +2080,11 @@ function file_upload_max_size() {
 
   if ($max_size < 0) {
     // Start with post_max_size.
-    $max_size = parse_size(ini_get('post_max_size'));
+    $max_size = parse_byte_count(ini_get('post_max_size'), TRUE);
 
     // If upload_max_size is less, then reduce. Except if upload_max_size is
     // zero, which indicates no limit.
-    $upload_max = parse_size(ini_get('upload_max_filesize'));
+    $upload_max = parse_byte_count(ini_get('upload_max_filesize'), TRUE);
     if ($upload_max > 0 && $upload_max < $max_size) {
       $max_size = $upload_max;
     }
diff --git a/core/includes/gettext.inc b/core/includes/gettext.inc
index 9398a5f..c4ed422 100644
--- a/core/includes/gettext.inc
+++ b/core/includes/gettext.inc
@@ -116,8 +116,8 @@ function _locale_import_read_po($op, $file, $mode = NULL, $lang = NULL) {
   $lineno = 0;
 
   while (!feof($fd)) {
-    // A line should not be longer than 10 * 1024.
-    $line = fgets($fd, 10 * 1024);
+    // A line should not be longer than 10 kibibytes.
+    $line = fgets($fd, 10 * DRUPAL_KIBIBYTE);
 
     if ($lineno == 0) {
       // The first line might come with a UTF-8 BOM, which should be removed.
diff --git a/core/modules/color/color.module b/core/modules/color/color.module
index 4a61b62..df9970e 100644
--- a/core/modules/color/color.module
+++ b/core/modules/color/color.module
@@ -324,9 +324,9 @@ function color_scheme_form_submit($form, &$form_state) {
     // memory_get_usage(), therefore we won't inadvertently reject a color
     // scheme change based on a faulty memory calculation.
     $usage = memory_get_usage(TRUE);
-    $limit = parse_size(ini_get('memory_limit'));
+    $limit = parse_byte_count(ini_get('memory_limit'), TRUE);
     if ($usage + $required > $limit) {
-      drupal_set_message(t('There is not enough memory available to PHP to change this theme\'s color scheme. You need at least %size more. Check the <a href="@url">PHP documentation</a> for more information.', array('%size' => format_size($usage + $required - $limit), '@url' => 'http://www.php.net/manual/ini.core.php#ini.sect.resource-limits')), 'error');
+      drupal_set_message(t('There is not enough memory available to PHP to change this theme\'s color scheme. You need at least %size more. Check the <a href="@url">PHP documentation</a> for more information.', array('%size' => format_byte_count($usage + $required - $limit), '@url' => 'http://www.php.net/manual/ini.core.php#ini.sect.resource-limits')), 'error');
       return;
     }
   }
diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc
index a46ed1a..4a90bd7 100644
--- a/core/modules/file/file.field.inc
+++ b/core/modules/file/file.field.inc
@@ -101,7 +101,7 @@ function file_field_instance_settings_form($field, $instance) {
     '#type' => 'textfield',
     '#title' => t('Maximum upload size'),
     '#default_value' => $settings['max_filesize'],
-    '#description' => t('Enter a value like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes) in order to restrict the allowed file size. If left empty the file sizes will be limited only by PHP\'s maximum post and file upload sizes (current limit <strong>%limit</strong>).', array('%limit' => format_size(file_upload_max_size()))),
+    '#description' => t('Enter a value like "512" (bytes), "80 kB" (kilobytes) or "50 MB" (megabytes) in order to restrict the allowed file size. If left empty the file sizes will be limited only by PHP\'s maximum post and file upload sizes (current limit <strong>%limit</strong>).', array('%limit' => format_byte_count(file_upload_max_size()))),
     '#size' => 10,
     '#element_validate' => array('_file_generic_settings_max_filesize'),
     '#weight' => 5,
@@ -123,14 +123,14 @@ function file_field_instance_settings_form($field, $instance) {
  * Render API callback: Validates the maximum uplodad size field.
  *
  * Ensures that a size has been entered and that it can be parsed by
- * parse_size().
+ * parse_byte_count().
  *
  * This function is assigned as an #element_validate callback in
  * file_field_instance_settings_form().
  */
 function _file_generic_settings_max_filesize($element, &$form_state) {
-  if (!empty($element['#value']) && !is_numeric(parse_size($element['#value']))) {
-    form_error($element, t('The "!name" option must contain a valid value. You may either leave the text field empty or enter a string like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes).', array('!name' => t($element['title']))));
+  if (!empty($element['#value']) && !parse_byte_count($element['#value'])) {
+    form_error($element, t('The "!name" option must contain a valid value. You may either leave the text field empty or enter a string like "512" (bytes), "80 kB" (kilobytes) or "50 MB" (megabytes).', array('!name' => t($element['title']))));
   }
 }
 
@@ -539,9 +539,9 @@ function file_field_widget_form(&$form, &$form_state, $field, $instance, $langco
  */
 function file_field_widget_upload_validators($field, $instance) {
   // Cap the upload size according to the PHP limit.
-  $max_filesize = parse_size(file_upload_max_size());
-  if (!empty($instance['settings']['max_filesize']) && parse_size($instance['settings']['max_filesize']) < $max_filesize) {
-    $max_filesize = parse_size($instance['settings']['max_filesize']);
+  $max_filesize = file_upload_max_size();
+  if (!empty($instance['settings']['max_filesize']) && parse_byte_count($instance['settings']['max_filesize']) < $max_filesize) {
+    $max_filesize = parse_byte_count($instance['settings']['max_filesize']);
   }
 
   $validators = array();
@@ -809,7 +809,7 @@ function theme_file_widget($variables) {
   $output .= '<div class="file-widget form-managed-file clearfix">';
   if ($element['fid']['#value'] != 0) {
     // Add the file size after the file name.
-    $element['filename']['#markup'] .= ' <span class="file-size">(' . format_size($element['#file']->filesize) . ')</span> ';
+    $element['filename']['#markup'] .= ' <span class="file-size">(' . format_byte_count($element['#file']->filesize) . ')</span> ';
   }
   $output .= drupal_render_children($element);
   $output .= '</div>';
@@ -945,7 +945,7 @@ function theme_file_upload_help($variables) {
     $descriptions[] = $description;
   }
   if (isset($upload_validators['file_validate_size'])) {
-    $descriptions[] = t('Files must be less than !size.', array('!size' => '<strong>' . format_size($upload_validators['file_validate_size'][0]) . '</strong>'));
+    $descriptions[] = t('Files must be less than !size.', array('!size' => '<strong>' . format_byte_count($upload_validators['file_validate_size'][0]) . '</strong>'));
   }
   if (isset($upload_validators['file_validate_extensions'])) {
     $descriptions[] = t('Allowed file types: !extensions.', array('!extensions' => '<strong>' . check_plain($upload_validators['file_validate_extensions'][0]) . '</strong>'));
@@ -1021,7 +1021,7 @@ function theme_file_formatter_table($variables) {
   foreach ($variables['items'] as $delta => $item) {
     $rows[] = array(
       theme('file_link', array('file' => (object) $item)),
-      format_size($item['filesize']),
+      format_byte_count($item['filesize']),
     );
   }
 
diff --git a/core/modules/file/file.module b/core/modules/file/file.module
index c951807..7551da1 100644
--- a/core/modules/file/file.module
+++ b/core/modules/file/file.module
@@ -240,7 +240,7 @@ function file_ajax_upload() {
 
   if (empty($_POST['form_build_id']) || $form_build_id != $_POST['form_build_id']) {
     // Invalid request.
-    drupal_set_message(t('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports.', array('@size' => format_size(file_upload_max_size()))), 'error');
+    drupal_set_message(t('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports.', array('@size' => format_byte_count(file_upload_max_size()))), 'error');
     $commands = array();
     $commands[] = ajax_command_replace(NULL, theme('status_messages'));
     return array('#type' => 'ajax', '#commands' => $commands);
@@ -307,14 +307,14 @@ function file_ajax_progress($key) {
   if ($implementation == 'uploadprogress') {
     $status = uploadprogress_get_info($key);
     if (isset($status['bytes_uploaded']) && !empty($status['bytes_total'])) {
-      $progress['message'] = t('Uploading... (@current of @total)', array('@current' => format_size($status['bytes_uploaded']), '@total' => format_size($status['bytes_total'])));
+      $progress['message'] = t('Uploading... (@current of @total)', array('@current' => format_byte_count($status['bytes_uploaded']), '@total' => format_byte_count($status['bytes_total'])));
       $progress['percentage'] = round(100 * $status['bytes_uploaded'] / $status['bytes_total']);
     }
   }
   elseif ($implementation == 'apc') {
     $status = apc_fetch('upload_' . $key);
     if (isset($status['current']) && !empty($status['total'])) {
-      $progress['message'] = t('Uploading... (@current of @total)', array('@current' => format_size($status['current']), '@total' => format_size($status['total'])));
+      $progress['message'] = t('Uploading... (@current of @total)', array('@current' => format_byte_count($status['current']), '@total' => format_byte_count($status['total'])));
       $progress['percentage'] = round(100 * $status['current'] / $status['total']);
     }
   }
diff --git a/core/modules/file/tests/file.test b/core/modules/file/tests/file.test
index 8dad362..2892170 100644
--- a/core/modules/file/tests/file.test
+++ b/core/modules/file/tests/file.test
@@ -867,17 +867,13 @@ class FileFieldValidateTestCase extends FileFieldTestCase {
     $field = field_info_field($field_name);
     $instance = field_info_instance('node', $field_name, $type_name);
 
-    $small_file = $this->getTestFile('text', 131072); // 128KB.
-    $large_file = $this->getTestFile('text', 1310720); // 1.2MB
+    $small_file = $this->getTestFile('text', 131072);  // 128KiB
+    $large_file = $this->getTestFile('text', 1310720);  // 1.25MiB
 
     // Test uploading both a large and small file with different increments.
-    $sizes = array(
-      '1M' => 1048576,
-      '1024K' => 1048576,
-      '1048576' => 1048576,
-    );
+    $sizes = array('1M', '1000K', '1000000');
 
-    foreach ($sizes as $max_filesize => $file_limit) {
+    foreach ($sizes as $max_filesize) {
       // Set the max file upload size.
       $this->updateFileField($field_name, $type_name, array('max_filesize' => $max_filesize));
       $instance = field_info_instance('node', $field_name, $type_name);
@@ -886,13 +882,13 @@ class FileFieldValidateTestCase extends FileFieldTestCase {
       $nid = $this->uploadNodeFile($small_file, $field_name, $type_name);
       $node = node_load($nid, NULL, TRUE);
       $node_file = (object) $node->{$field_name}[LANGUAGE_NONE][0];
-      $this->assertFileExists($node_file, t('File exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->filesize), '%maxsize' => $max_filesize)));
-      $this->assertFileEntryExists($node_file, t('File entry exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->filesize), '%maxsize' => $max_filesize)));
+      $this->assertFileExists($node_file, t('File exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_byte_count($small_file->filesize), '%maxsize' => $max_filesize)));
+      $this->assertFileEntryExists($node_file, t('File entry exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_byte_count($small_file->filesize), '%maxsize' => $max_filesize)));
 
       // Check that uploading the large file fails (1M limit).
       $nid = $this->uploadNodeFile($large_file, $field_name, $type_name);
-      $error_message = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size($large_file->filesize), '%maxsize' => format_size($file_limit)));
-      $this->assertRaw($error_message, t('Node save failed when file (%filesize) exceeded the max upload size (%maxsize).', array('%filesize' => format_size($large_file->filesize), '%maxsize' => $max_filesize)));
+      $error_message = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_byte_count($large_file->filesize), '%maxsize' => format_byte_count(parse_byte_count($max_filesize))));
+      $this->assertRaw($error_message, t('Node save failed when file (%filesize) exceeded the max upload size (%maxsize).', array('%filesize' => format_byte_count($large_file->filesize), '%maxsize' => $max_filesize)));
     }
 
     // Turn off the max filesize.
@@ -902,8 +898,8 @@ class FileFieldValidateTestCase extends FileFieldTestCase {
     $nid = $this->uploadNodeFile($large_file, $field_name, $type_name);
     $node = node_load($nid, NULL, TRUE);
     $node_file = (object) $node->{$field_name}[LANGUAGE_NONE][0];
-    $this->assertFileExists($node_file, t('File exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->filesize))));
-    $this->assertFileEntryExists($node_file, t('File entry exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->filesize))));
+    $this->assertFileExists($node_file, t('File exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_byte_count($large_file->filesize))));
+    $this->assertFileEntryExists($node_file, t('File entry exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_byte_count($large_file->filesize))));
 
     // Remove our file field.
     field_delete_field($field_name);
@@ -1082,7 +1078,7 @@ class FileTokenReplaceTestCase extends FileFieldTestCase {
     $tests['[file:name]'] = check_plain($file->filename);
     $tests['[file:path]'] = check_plain($file->uri);
     $tests['[file:mime]'] = check_plain($file->filemime);
-    $tests['[file:size]'] = format_size($file->filesize);
+    $tests['[file:size]'] = format_byte_count($file->filesize);
     $tests['[file:url]'] = check_plain(file_create_url($file->uri));
     $tests['[file:timestamp]'] = format_date($file->timestamp, 'medium', '', NULL, $language->langcode);
     $tests['[file:timestamp:short]'] = format_date($file->timestamp, 'short', '', NULL, $language->langcode);
@@ -1101,7 +1097,7 @@ class FileTokenReplaceTestCase extends FileFieldTestCase {
     $tests['[file:name]'] = $file->filename;
     $tests['[file:path]'] = $file->uri;
     $tests['[file:mime]'] = $file->filemime;
-    $tests['[file:size]'] = format_size($file->filesize);
+    $tests['[file:size]'] = format_byte_count($file->filesize);
 
     foreach ($tests as $input => $expected) {
       $output = token_replace($input, array('file' => $file), array('language' => $language, 'sanitize' => FALSE));
diff --git a/core/modules/image/image.field.inc b/core/modules/image/image.field.inc
index aef6be7..a8eac6c 100644
--- a/core/modules/image/image.field.inc
+++ b/core/modules/image/image.field.inc
@@ -443,7 +443,7 @@ function theme_image_widget($variables) {
 
   $output .= '<div class="image-widget-data">';
   if ($element['fid']['#value'] != 0) {
-    $element['filename']['#markup'] .= ' <span class="file-size">(' . format_size($element['#file']->filesize) . ')</span> ';
+    $element['filename']['#markup'] .= ' <span class="file-size">(' . format_byte_count($element['#file']->filesize) . ')</span> ';
   }
   $output .= drupal_render_children($element);
   $output .= '</div>';
diff --git a/core/modules/image/image.test b/core/modules/image/image.test
index 4d4532c..d285ddf 100644
--- a/core/modules/image/image.test
+++ b/core/modules/image/image.test
@@ -738,7 +738,7 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
     $instance_settings = array(
       'alt_field' => 1,
       'file_extensions' => $test_image_extension,
-      'max_filesize' => '50 KB',
+      'max_filesize' => '50 kB',
       'max_resolution' => '100x100',
       'min_resolution' => '10x10',
       'title_field' => 1,
@@ -753,7 +753,7 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
     $instance = field_info_instance('node', $field_name, 'article');
 
     $this->drupalGet('node/add/article');
-    $this->assertText(t('Files must be less than 50 KB.'), t('Image widget max file size is displayed on article form.'));
+    $this->assertText(t('Files must be less than 50 kB.'), t('Image widget max file size is displayed on article form.'));
     $this->assertText(t('Allowed file types: ' . $test_image_extension . '.'), t('Image widget allowed file types displayed on article form.'));
     $this->assertText(t('Images must be between 10x10 and 100x100 pixels.'), t('Image widget allowed resolution displayed on article form.'));
 
diff --git a/core/modules/simpletest/drupal_web_test_case.php b/core/modules/simpletest/drupal_web_test_case.php
index c9fc562..f5a3eb0 100644
--- a/core/modules/simpletest/drupal_web_test_case.php
+++ b/core/modules/simpletest/drupal_web_test_case.php
@@ -1688,7 +1688,7 @@ class DrupalWebTestCase extends DrupalTestCase {
       '!method' => !empty($curl_options[CURLOPT_NOBODY]) ? 'HEAD' : (empty($curl_options[CURLOPT_POSTFIELDS]) ? 'GET' : 'POST'),
       '@url' => isset($original_url) ? $original_url : $url,
       '@status' => $status,
-      '!length' => format_size(strlen($this->drupalGetContent()))
+      '!length' => format_byte_count(strlen($this->drupalGetContent()))
     );
     $message = t('!method @url returned @status (!length).', $message_vars);
     $this->assertTrue($this->drupalGetContent() !== FALSE, $message, t('Browser'));
diff --git a/core/modules/simpletest/simpletest.install b/core/modules/simpletest/simpletest.install
index 96cc011..7e74ddf 100644
--- a/core/modules/simpletest/simpletest.install
+++ b/core/modules/simpletest/simpletest.install
@@ -63,7 +63,7 @@ function simpletest_requirements($phase) {
   // Check the current memory limit. If it is set too low, SimpleTest will fail
   // to load all tests and throw a fatal error.
   $memory_limit = ini_get('memory_limit');
-  if ($memory_limit && $memory_limit != -1 && parse_size($memory_limit) < parse_size(SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT)) {
+  if ($memory_limit && $memory_limit != -1 && parse_byte_count($memory_limit, TRUE) < parse_byte_count(SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT, TRUE)) {
     $requirements['php_memory_limit']['severity'] = REQUIREMENT_ERROR;
     $requirements['php_memory_limit']['description'] = $t('The testing framework requires the PHP memory limit to be at least %memory_minimum_limit. The current value is %memory_limit. <a href="@url">Follow these steps to continue</a>.', array('%memory_limit' => $memory_limit, '%memory_minimum_limit' => SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT, '@url' => 'http://drupal.org/node/207036'));
   }
diff --git a/core/modules/simpletest/tests/common.test b/core/modules/simpletest/tests/common.test
index d6f19c7..7063a58 100644
--- a/core/modules/simpletest/tests/common.test
+++ b/core/modules/simpletest/tests/common.test
@@ -425,36 +425,55 @@ class CommonXssUnitTestCase extends DrupalUnitTestCase {
 }
 
 /**
- * Tests file size parsing and formatting functions.
+ * Tests byte count parsing and formatting functions.
  */
-class CommonSizeUnitTestCase extends DrupalUnitTestCase {
+class CommonByteCountUnitTestCase extends DrupalUnitTestCase {
   protected $exact_test_cases;
   protected $rounded_test_cases;
 
   public static function getInfo() {
     return array(
-      'name' => 'Size parsing test',
+      'name' => 'Byte count parsing and formatting',
       'description' => 'Parse a predefined amount of bytes and compare the output with the expected value.',
       'group' => 'Common',
     );
   }
 
   function setUp() {
-    $kb = DRUPAL_KILOBYTE;
     $this->exact_test_cases = array(
-      '1 byte' => 1,
-      '1 KB'   => $kb,
-      '1 MB'   => $kb * $kb,
-      '1 GB'   => $kb * $kb * $kb,
-      '1 TB'   => $kb * $kb * $kb * $kb,
-      '1 PB'   => $kb * $kb * $kb * $kb * $kb,
-      '1 EB'   => $kb * $kb * $kb * $kb * $kb * $kb,
-      '1 ZB'   => $kb * $kb * $kb * $kb * $kb * $kb * $kb,
-      '1 YB'   => $kb * $kb * $kb * $kb * $kb * $kb * $kb * $kb,
+      '1 B' => 1,
+      '1 kB' => DRUPAL_KILOBYTE,
+      '1 MB' => pow(DRUPAL_KILOBYTE, 2),
+      '1 GB' => pow(DRUPAL_KILOBYTE, 3),
+      '1 TB' => pow(DRUPAL_KILOBYTE, 4),
+      '1 PB' => pow(DRUPAL_KILOBYTE, 5),
+      '1 EB' => pow(DRUPAL_KILOBYTE, 6),
+      '1 ZB' => pow(DRUPAL_KILOBYTE, 7),
+      '1 YB' => pow(DRUPAL_KILOBYTE, 8),
+    );
+    $this->exact_iec_test_cases = array(
+      '1 KiB' => DRUPAL_KIBIBYTE,
+      '1 MiB' => pow(DRUPAL_KIBIBYTE, 2),
+      '1 GiB' => pow(DRUPAL_KIBIBYTE, 3),
+      '1 TiB' => pow(DRUPAL_KIBIBYTE, 4),
+      '1 PiB' => pow(DRUPAL_KIBIBYTE, 5),
+      '1 EiB' => pow(DRUPAL_KIBIBYTE, 6),
+      '1 ZiB' => pow(DRUPAL_KIBIBYTE, 7),
+      '1 YiB' => pow(DRUPAL_KIBIBYTE, 8),
+    );
+    $this->exact_force_iec_test_cases = array(
+      '1 kB' => DRUPAL_KIBIBYTE,
+      '1 MB' => pow(DRUPAL_KIBIBYTE, 2),
+      '1 GB' => pow(DRUPAL_KIBIBYTE, 3),
+      '1 TB' => pow(DRUPAL_KIBIBYTE, 4),
+      '1 PB' => pow(DRUPAL_KIBIBYTE, 5),
+      '1 EB' => pow(DRUPAL_KIBIBYTE, 6),
+      '1 ZB' => pow(DRUPAL_KIBIBYTE, 7),
+      '1 YB' => pow(DRUPAL_KIBIBYTE, 8),
     );
     $this->rounded_test_cases = array(
-      '2 bytes' => 2,
-      '1 MB' => ($kb * $kb) - 1, // rounded to 1 MB (not 1000 or 1024 kilobyte!)
+      '2 B' => 2,
+      '1 MB' => DRUPAL_KILOBYTE * DRUPAL_KILOBYTE + 1, // rounded to 1 MB (not 1000 or 1024 kilobyte!)
       round(3623651 / ($this->exact_test_cases['1 MB']), 2) . ' MB' => 3623651, // megabytes
       round(67234178751368124 / ($this->exact_test_cases['1 PB']), 2) . ' PB' => 67234178751368124, // petabytes
       round(235346823821125814962843827 / ($this->exact_test_cases['1 YB']), 2) . ' YB' => 235346823821125814962843827, // yottabytes
@@ -463,13 +482,13 @@ class CommonSizeUnitTestCase extends DrupalUnitTestCase {
   }
 
   /**
-   * Check that format_size() returns the expected string.
+   * Check that format_byte_count() returns the expected string.
    */
-  function testCommonFormatSize() {
+  function testCommonFormatByteCount() {
     foreach (array($this->exact_test_cases, $this->rounded_test_cases) as $test_cases) {
       foreach ($test_cases as $expected => $input) {
         $this->assertEqual(
-          ($result = format_size($input, NULL)),
+          ($result = format_byte_count($input)),
           $expected,
           $expected . ' == ' . $result . ' (' . $input . ' bytes)'
         );
@@ -478,12 +497,22 @@ class CommonSizeUnitTestCase extends DrupalUnitTestCase {
   }
 
   /**
-   * Check that parse_size() returns the proper byte sizes.
+   * Check that parse_byte_count() returns the proper byte sizes.
    */
-  function testCommonParseSize() {
-    foreach ($this->exact_test_cases as $string => $size) {
+  function testCommonParseByteCount() {
+    foreach (array($this->exact_test_cases, $this->exact_iec_test_cases) as $test_cases) {
+      foreach ($test_cases as $string => $size) {
+        $this->assertEqual(
+          $parsed_size = parse_byte_count($string),
+          $size,
+          $size . ' == ' . $parsed_size . ' (' . $string . ')'
+        );
+      }
+    }
+
+    foreach ($this->exact_force_iec_test_cases as $string => $size) {
       $this->assertEqual(
-        $parsed_size = parse_size($string),
+        $parsed_size = parse_byte_count($string, TRUE),
         $size,
         $size . ' == ' . $parsed_size . ' (' . $string . ')'
       );
@@ -492,32 +521,32 @@ class CommonSizeUnitTestCase extends DrupalUnitTestCase {
     // Some custom parsing tests
     $string = '23476892 bytes';
     $this->assertEqual(
-      ($parsed_size = parse_size($string)),
+      ($parsed_size = parse_byte_count($string)),
       $size = 23476892,
       $string . ' == ' . $parsed_size . ' bytes'
     );
     $string = '76MRandomStringThatShouldBeIgnoredByParseSize.'; // 76 MB
     $this->assertEqual(
-      $parsed_size = parse_size($string),
-      $size = 79691776,
+      $parsed_size = parse_byte_count($string),
+      $size = 76000000,
       $string . ' == ' . $parsed_size . ' bytes'
     );
-    $string = '76.24 Giggabyte'; // Misspeld text -> 76.24 GB
+    $string = '76.24 Gubibytes'; // Misspeld text -> 76.24 GiB
     $this->assertEqual(
-      $parsed_size = parse_size($string),
-      $size = 81862076662,
+      $parsed_size = parse_byte_count($string),
+      $size = 81862076661,
       $string . ' == ' . $parsed_size . ' bytes'
     );
   }
 
   /**
-   * Cross-test parse_size() and format_size().
+   * Cross-test parse_byte_count() and format_byte_count().
    */
-  function testCommonParseSizeFormatSize() {
+  function testCommonParseFormatByteCount() {
     foreach ($this->exact_test_cases as $size) {
       $this->assertEqual(
         $size,
-        ($parsed_size = parse_size($string = format_size($size, NULL))),
+        ($parsed_size = parse_byte_count($string = format_byte_count($size))),
         $size . ' == ' . $parsed_size . ' (' . $string . ')'
       );
     }
diff --git a/core/modules/simpletest/tests/file.test b/core/modules/simpletest/tests/file.test
index a369a44..e40fa0a 100644
--- a/core/modules/simpletest/tests/file.test
+++ b/core/modules/simpletest/tests/file.test
@@ -495,9 +495,9 @@ class FileValidatorTest extends DrupalWebTestCase {
     // Run these tests as a regular user.
     $user = $this->drupalCreateUser();
 
-    // Create a file with a size of 1000 bytes, and quotas of only 1 byte.
+    // Create a file with a size of 1kB, and quotas of only 1 byte.
     $file = new stdClass();
-    $file->filesize = 1000;
+    $file->filesize = DRUPAL_KILOBYTE;
     $errors = file_validate_size($file, 0, 0);
     $this->assertEqual(count($errors), 0, t('No limits means no errors.'), 'File');
     $errors = file_validate_size($file, 1, 0);
diff --git a/core/modules/simpletest/tests/xmlrpc.test b/core/modules/simpletest/tests/xmlrpc.test
index 60b9624..95764b4 100644
--- a/core/modules/simpletest/tests/xmlrpc.test
+++ b/core/modules/simpletest/tests/xmlrpc.test
@@ -217,7 +217,7 @@ class XMLRPCMessagesTestCase extends DrupalWebTestCase {
       $xml_message_l = xmlrpc_test_message_sized_in_kb($size);
       $xml_message_r = xmlrpc($xml_url, array('messages.messageSizedInKB' => array($size)));
 
-      $this->assertEqual($xml_message_l, $xml_message_r, t('XML-RPC messages.messageSizedInKB of %s Kb size received', array('%s' => $size)));
+      $this->assertEqual($xml_message_l, $xml_message_r, t('XML-RPC messages.messageSizedInKB of %s kB size received', array('%s' => $size)));
     }
   }
 
diff --git a/core/modules/simpletest/tests/xmlrpc_test.module b/core/modules/simpletest/tests/xmlrpc_test.module
index db8f113..9b7c363 100644
--- a/core/modules/simpletest/tests/xmlrpc_test.module
+++ b/core/modules/simpletest/tests/xmlrpc_test.module
@@ -86,10 +86,10 @@ function xmlrpc_test_xmlrpc_alter(&$services) {
 }
 
 /**
- * Created a message of the desired size in KB.
+ * Created a message of the desired size in kB.
  *
  * @param $size
- *   Message size in KB.
+ *   Message size in kB.
  * @return array
  *   Generated message structure.
  */
@@ -98,7 +98,7 @@ function xmlrpc_test_message_sized_in_kb($size) {
 
   $word = 'abcdefg';
 
-  // Create a ~1KB sized struct.
+  // Create a ~1kB sized struct.
   for ($i = 0 ; $i < 128; $i++) {
     $line['word_' . $i] = $word;
   }
diff --git a/core/modules/system/system.install b/core/modules/system/system.install
index 7a275e8..8fd0692 100644
--- a/core/modules/system/system.install
+++ b/core/modules/system/system.install
@@ -199,7 +199,7 @@ function system_requirements($phase) {
     'value' => $memory_limit == -1 ? t('-1 (Unlimited)') : $memory_limit,
   );
 
-  if ($memory_limit && $memory_limit != -1 && parse_size($memory_limit) < parse_size(DRUPAL_MINIMUM_PHP_MEMORY_LIMIT)) {
+  if ($memory_limit && $memory_limit != -1 && parse_byte_count($memory_limit, TRUE) < parse_byte_count(DRUPAL_MINIMUM_PHP_MEMORY_LIMIT, TRUE)) {
     $description = '';
     if ($phase == 'install') {
       $description = $t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the installation process.', array('%memory_minimum_limit' => DRUPAL_MINIMUM_PHP_MEMORY_LIMIT));
diff --git a/core/modules/system/system.tokens.inc b/core/modules/system/system.tokens.inc
index fa95661..fe15de1 100644
--- a/core/modules/system/system.tokens.inc
+++ b/core/modules/system/system.tokens.inc
@@ -236,7 +236,7 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a
           break;
 
         case 'size':
-          $replacements[$original] = format_size($file->filesize);
+          $replacements[$original] = format_byte_count($file->filesize);
           break;
 
         case 'url':
diff --git a/core/modules/user/user.admin.inc b/core/modules/user/user.admin.inc
index f7d4552..28334b3 100644
--- a/core/modules/user/user.admin.inc
+++ b/core/modules/user/user.admin.inc
@@ -406,7 +406,7 @@ function user_admin_settings() {
     '#default_value' => variable_get('user_picture_file_size', '30'),
     '#size' => 10,
     '#maxlength' => 10,
-    '#field_suffix' => ' ' . t('KB'),
+    '#field_suffix' => ' ' . t('kB'),
     '#description' => t('Maximum allowed file size for uploaded pictures. Upload size is normally limited only by the PHP maximum post and file upload settings, and images are automatically scaled down to the dimensions specified above.'),
   );
   $form['personalization']['pictures']['user_picture_guidelines'] = array(
diff --git a/core/modules/user/user.module b/core/modules/user/user.module
index 928daad..46ee828 100644
--- a/core/modules/user/user.module
+++ b/core/modules/user/user.module
@@ -638,7 +638,7 @@ function user_validate_picture(&$form, &$form_state) {
   $validators = array(
     'file_validate_is_image' => array(),
     'file_validate_image_resolution' => array(variable_get('user_picture_dimensions', '85x85')),
-    'file_validate_size' => array(variable_get('user_picture_file_size', '30') * 1024),
+    'file_validate_size' => array(variable_get('user_picture_file_size', '30') * DRUPAL_KILOBYTE),
   );
 
   // Save the file as a temporary file.
diff --git a/core/modules/user/user.test b/core/modules/user/user.test
index 367bf82..7465d4c 100644
--- a/core/modules/user/user.test
+++ b/core/modules/user/user.test
@@ -935,7 +935,7 @@ class UserPictureTestCase extends DrupalWebTestCase {
       $this->drupalLogin($this->user);
 
       // Images are sorted first by size then by name. We need an image
-      // bigger than 1 KB so we'll grab the last one.
+      // bigger than 1 kB so we'll grab the last one.
       $files = $this->drupalGetTestFiles('image');
       $image = end($files);
       $info = image_get_info($image->uri);
@@ -951,7 +951,7 @@ class UserPictureTestCase extends DrupalWebTestCase {
       // Test that the upload failed and that the correct reason was cited.
       $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename));
       $this->assertRaw($text, t('Upload failed.'));
-      $text = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size(filesize($image->uri)), '%maxsize' => format_size($test_size * 1024)));
+      $text = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_byte_count(filesize($image->uri)), '%maxsize' => format_byte_count($test_size * DRUPAL_KILOBYTE)));
       $this->assertRaw($text, t('File size cited as reason for failure.'));
 
       // Check if file is not uploaded.
@@ -1016,7 +1016,7 @@ class UserPictureTestCase extends DrupalWebTestCase {
       // Test that the upload failed and that the correct reason was cited.
       $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename));
       $this->assertRaw($text, t('Upload failed.'));
-      $text = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size(filesize($image->uri)), '%maxsize' => format_size($test_size * 1024)));
+      $text = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_byte_count(filesize($image->uri)), '%maxsize' => format_byte_count($test_size * DRUPAL_KILOBYTE)));
       $this->assertRaw($text, t('File size cited as reason for failure.'));
 
       // Check if file is not uploaded.
