亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2122 | 回復(fù): 6
打印 上一主題 下一主題

關(guān)于,對不足8位的在后面補二進(jìn)制的0 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2004-08-25 12:39 |只看該作者 |倒序瀏覽
如字符:45045  如何在后面補二進(jìn)制的0 并且成為8位數(shù),
請問如何實現(xiàn)?

thx all!

論壇徽章:
1
榮譽版主
日期:2011-11-23 16:44:17
2 [報告]
發(fā)表于 2004-08-25 12:46 |只看該作者

關(guān)于,對不足8位的在后面補二進(jìn)制的0


  1. function FillBit($source, $length, $fill = '0', $lor = 'l')
  2. {
  3.     $source_len = strlen($source);

  4.     if ( ($length - $source_len) >; 0 ){
  5.         if ( $lor == 'l' ){
  6.             $result = str_repeat($fill, $length - $source_len) . $source;
  7.         }else{
  8.             $result = $source . str_repeat($fill, $length - $source_len);
  9.         }
  10.     }else{
  11.         $result = $source;
  12.     }

  13.     return $result;
  14. }

  15. $result = FillBit($source, 8, '0', 'r');
復(fù)制代碼

論壇徽章:
0
3 [報告]
發(fā)表于 2004-08-25 13:09 |只看該作者

關(guān)于,對不足8位的在后面補二進(jìn)制的0

謝謝!原來直接在后面加0就可以了?

論壇徽章:
1
技術(shù)圖書徽章
日期:2013-12-05 23:25:45
4 [報告]
發(fā)表于 2004-08-25 15:43 |只看該作者

關(guān)于,對不足8位的在后面補二進(jìn)制的0

你的這個太簡單了哦:
  1. <?php
  2. $strSource = "45045";
  3. $strDist = sprintf("%-08s",$strSource);//-表示在后面補,0表示補0,8表示程度為8,s表示字符串
  4. echo $strDist;
  5. ?>;
復(fù)制代碼


真是受不了阿,居然不看幫助文檔不官方手冊:
http://w.yi.org/ftp/FAPM/PHP/zh-php4/function.php-sprintf.htm

  1. sprintf
  2. 將字符串格式化。

  3. 語法: string sprintf(string format, mixed [args]...);

  4. 返回值: 字符串

  5. 函數(shù)種類: 資料處理




  6. 內(nèi)容說明


  7. 本函數(shù)用來將字符串格式化。參數(shù) format 是轉(zhuǎn)換的格式,以百分比符號 % 開始到轉(zhuǎn)換字符為止。而在轉(zhuǎn)換的格式間依序包括了


  8. 填空字符。0 的話表示空格填 0;空格是默認(rèn)值,表示空格就放著。
  9. 對齊方式。默認(rèn)值為向右對齊,負(fù)號表向左對齊。
  10. 字段寬度。為最小寬度。
  11. 精確度。指在小數(shù)點后的浮點數(shù)位數(shù)。
  12. 類型,見下表 % 印出百分比符號,不轉(zhuǎn)換。
  13. b 整數(shù)轉(zhuǎn)成二進(jìn)位。
  14. c 整數(shù)轉(zhuǎn)成對應(yīng)的 ASCII 字符。
  15. d 整數(shù)轉(zhuǎn)成十進(jìn)位。
  16. f 倍精確度數(shù)字轉(zhuǎn)成浮點數(shù)。
  17. o 整數(shù)轉(zhuǎn)成八進(jìn)位。
  18. s 整數(shù)轉(zhuǎn)成字符串。
  19. x 整數(shù)轉(zhuǎn)成小寫十六進(jìn)位。
  20. X 整數(shù)轉(zhuǎn)成大寫十六進(jìn)位。




  21. 使用范例


  22. <?
  23. $money1 = 68.75;
  24. $money2 = 54.35;
  25. $money = $money1 + $money2;
  26. // 此時變量 $money 值為 "123.1";
  27. $formatted = sprintf ("%01.2f", $money);
  28. // 此時變量 $ formatted 值為 "123.10"
  29. ?>;
復(fù)制代碼

論壇徽章:
0
5 [報告]
發(fā)表于 2004-08-25 16:05 |只看該作者

關(guān)于,對不足8位的在后面補二進(jìn)制的0

45045 Or 11110000

論壇徽章:
0
6 [報告]
發(fā)表于 2004-08-25 17:23 |只看該作者

關(guān)于,對不足8位的在后面補二進(jìn)制的0

我也加一個

str_pad
(PHP 4 >;= 4.0.1)

str_pad --  Pad a string to a certain length with another string
Description
string str_pad ( string input, int pad_length [, string pad_string [, int pad_type]])


This functions returns the input string padded on the left, the right, or both sides to the specified padding length. If the optional argument pad_string is not supplied, the input is padded with spaces, otherwise it is padded with characters from pad_string up to the limit.

Optional argument pad_type can be STR_PAD_RIGHT, STR_PAD_LEFT, or STR_PAD_BOTH. If pad_type is not specified it is assumed to be STR_PAD_RIGHT.

If the value of pad_length is negative or less than the length of the input string, no padding takes place.

例子 1. str_pad() example

  1. <?php
  2. $input = "Alien";
  3. echo str_pad($input, 10);                      // produces "Alien     "
  4. echo str_pad($input, 10, "-=", STR_PAD_LEFT);  // produces "-=-=-Alien"
  5. echo str_pad($input, 10, "_", STR_PAD_BOTH);   // produces "__Alien___"
  6. echo str_pad($input, 6 , "___");               // produces "Alien_"
  7. ?>;  
復(fù)制代碼



注: The pad_string may be truncated if the required number of padding characters can't be evenly divided by the pad_string's length.

手冊上都有

論壇徽章:
0
7 [報告]
發(fā)表于 2004-08-25 17:26 |只看該作者

關(guān)于,對不足8位的在后面補二進(jìn)制的0

str_pad
(PHP 4 >;= 4.0.1)

str_pad --  Pad a string to a certain length with another string
Description
string str_pad ( string input, int pad_length [, string pad_string [, int pad_type]])


This functions returns the input string padded on the left, the right, or both sides to the specified padding length. If the optional argument pad_string is not supplied, the input is padded with spaces, otherwise it is padded with characters from pad_string up to the limit.

Optional argument pad_type can be STR_PAD_RIGHT, STR_PAD_LEFT, or STR_PAD_BOTH. If pad_type is not specified it is assumed to be STR_PAD_RIGHT.

If the value of pad_length is negative or less than the length of the input string, no padding takes place.

例子 1. str_pad() example

  1. <?php
  2. $input = "Alien";
  3. echo str_pad($input, 10);                      // produces "Alien     "
  4. echo str_pad($input, 10, "-=", STR_PAD_LEFT);  // produces "-=-=-Alien"
  5. echo str_pad($input, 10, "_", STR_PAD_BOTH);   // produces "__Alien___"
  6. echo str_pad($input, 6 , "___");               // produces "Alien_"
  7. ?>;  
復(fù)制代碼



注: The pad_string may be truncated if the required number of padding characters can't be evenly divided by the pad_string's length.
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP