常用鏈接

          統(tǒng)計(jì)

          最新評(píng)論

          #

          perl print @

          #!/usr/bin/perl
          @rocks=qw(ab cd ef gh);
          print @rocks; #打印出abcdefgh
          print @rocks."\n"; #打印4

          posted @ 2009-02-18 15:00 九寶 閱讀(345) | 評(píng)論 (0)編輯 收藏

          關(guān)于java的JIT知識(shí)(轉(zhuǎn))

          什么是JIT?

          JIT是just in time,即時(shí)編譯技術(shù)。使用該技術(shù),能夠加速java程序的執(zhí)行速度。下面,就對(duì)該技術(shù)做個(gè)簡單的講解。

          首先,我們大家都知道,通常javac將程序源代碼編譯,轉(zhuǎn)換成java字節(jié)碼,JVM通過解釋字節(jié)碼將其翻譯成對(duì)應(yīng)的機(jī)器指令,逐條讀入,逐條解釋翻譯。很顯然,經(jīng)過解釋執(zhí)行,其執(zhí)行速度必然會(huì)比可執(zhí)行的二進(jìn)制字節(jié)碼程序慢。為了提高執(zhí)行速度,引入了JIT技術(shù)。

          在運(yùn)行時(shí)JIT會(huì)把翻譯過的機(jī)器碼保存起來,已備下次使用,因此從理論上來說,采用該JIT技術(shù)可以,可以接近以前純編譯技術(shù)。下面我看看,JIT的工作過程。

          JIT 編譯過程

          當(dāng)JIT編譯啟用時(shí)(默認(rèn)是啟用的),JVM讀入.class文件解釋后,將其發(fā)給JIT編譯器。JIT編譯器將字節(jié)碼編譯成本機(jī)機(jī)器代碼,下圖展示了該過程。

          什么是JIT?

          JIT是just in time,即時(shí)編譯技術(shù)。使用該技術(shù),能夠加速java程序的執(zhí)行速度。下面,就對(duì)該技術(shù)做個(gè)簡單的講解。

          首先,我們大家都知道,通常javac將程序源代碼編譯,轉(zhuǎn)換成java字節(jié)碼,JVM通過解釋字節(jié)碼將其翻譯成對(duì)應(yīng)的機(jī)器指令,逐條讀入,逐條解釋翻譯。很顯然,經(jīng)過解釋執(zhí)行,其執(zhí)行速度必然會(huì)比可執(zhí)行的二進(jìn)制字節(jié)碼程序慢。為了提高執(zhí)行速度,引入了JIT技術(shù)。

          在運(yùn)行時(shí)JIT會(huì)把翻譯過的機(jī)器碼保存起來,已備下次使用,因此從理論上來說,采用該JIT技術(shù)可以,可以接近以前純編譯技術(shù)。下面我看看,JIT的工作過程。

          JIT 編譯過程

          當(dāng)JIT編譯啟用時(shí)(默認(rèn)是啟用的),JVM讀入.class文件解釋后,將其發(fā)給JIT編譯器。JIT編譯器將字節(jié)碼編譯成本機(jī)機(jī)器代碼,下圖展示了該過程。


          Graphic

           

          通過上面的解釋,我們了解了JIT的工作原理及過程,同樣也發(fā)現(xiàn)了個(gè)問題,由于JIT對(duì)每條字節(jié)碼都進(jìn)行編譯,造成了編譯過程負(fù)擔(dān)過重。為了避免這種情況,當(dāng)前的JIT只對(duì)經(jīng)常執(zhí)行的字節(jié)碼進(jìn)行編譯,如循環(huán)等。

          需要說明的是,JIT并不總是奏效,不能期望JIT一定能夠加速你代碼執(zhí)行的速度,更糟糕的是她有可能降低代碼的執(zhí)行速度。這取決于你的代碼結(jié)構(gòu),當(dāng)然很多情況下我們還是能夠如愿以償?shù)摹?/p>

          posted @ 2009-01-13 14:18 九寶 閱讀(2140) | 評(píng)論 (0)編輯 收藏

          [Embedded]嵌入式 Linux 的根文件系統(tǒng) - rootfs (轉(zhuǎn))

          * 嵌入式系統(tǒng)中主要的存儲(chǔ)介質(zhì) Flash 是稀有資源,為數(shù)不多的 RAM 也是。在嵌入式
          系統(tǒng)開發(fā)中,開發(fā)人員十分珍惜這兩種資源,也想出了許多辦法解決資源短缺的問題。
          * Linux 中,rootfs 是必不可少的。PC 上主要實(shí)現(xiàn)有 ramdisk 和直接掛載 HD(
          Harddisk,硬盤) 上的根文件系統(tǒng);嵌入式中一般不從 HD 啟動(dòng),而是從 Flash 啟
          動(dòng),最簡單的方法是將 rootfs load 到 RAM 的 RAMDisk,稍復(fù)雜的就是 直接從
          Flash 讀取的 Cramfs,更復(fù)雜的是在 Flash 上分區(qū),并構(gòu)建 JFFS2 等文件系統(tǒng)。
          * RAMDisk 將制作好的 rootfs 壓縮后寫入 Flash,啟動(dòng)的時(shí)候由 Bootloader load 到
          RAM,解壓縮,然后掛載到 /。這種方法操作簡單,但是在 RAM 中的文件系統(tǒng)不是壓
          縮的,因此需要占用許多嵌入式系統(tǒng)中稀有資源 RAM。
          * initrd 是 RAMDisk 的格式,kernel 2.4 之前都是 image-initrd,Kernel 2.5 引入
          了 cpio-initrd,大大簡化了 Linux 的啟動(dòng)過程,附合 Linux 的基本哲學(xué):Keep it
          simple, stupid(KISS). 不過,cpio-initrd 作為新的格式,還沒有經(jīng)過廣泛測(cè)試,
          嵌入式 Linux 中主要采用的還是 image-initrd。
          * Cramfs 是 Linus 寫的很簡單的文件系統(tǒng),有很好的壓縮綠,也可以直接從 Flash 上
          運(yùn)行,不須 load 到 RAM 中,因此節(jié)約了 RAM。但是 Cramfs 是只讀的,對(duì)于需要運(yùn)
          行時(shí)修改的目錄(如: /etc, /var, /tmp)多有不便,因此,一般將這些目錄做成
          ramfs 等可寫的 fs。
          * SquashFS 是對(duì) Cramfs 的增強(qiáng)。突破了 Cramfs 的一些限制,在 Flash 和 RAM 的使
          用量方面也具有優(yōu)勢(shì)。不過,據(jù)開發(fā)者介紹,在性能上可能不如 Cramfs。這也是一種
          新方法,在嵌入式系統(tǒng)采用之前,需要經(jīng)過更多的測(cè)試。
          * XIP(exece-in-place,就地運(yùn)行) 是一種不須將應(yīng)用程序 load 到 RAM 就可以運(yùn)行
          的技術(shù),無疑可以減少 RAM 的使用。不過在嵌入式系統(tǒng)我還沒有遇到這種技術(shù)的使用

          posted @ 2008-12-29 16:58 九寶 閱讀(909) | 評(píng)論 (0)編輯 收藏

          ClearCase簡單使用 (轉(zhuǎn))

          1. When you come to work, the first thing you need to do is: Create a View
             Command:
           

          ct mkview -tag <view_tag> <view_storage_path>

             example:

          ct mkview -tag alex_test /net/nj2/

             Other Command:

          ct lsview                  list all the views reside in the hosts

          ct lsview | grep name      list specified view by name

          ct rmview -tag <view_tag>  remove an exist view

          2. After you create a vew, you need to Set the View to enter it. Then you are able to see the vob content only when you set the view.

          ct setview <view_tag>

          Example:

          ct setview alex_test

          Other Commands

          ct pwv                     see which view you are currently in

          exit                       quit from current view

          3. When you are in a view, you need to set the config spec correctly to pick up the right version of element.

          ct catcs                   view your config spec

          ct edcs                    edit your config spec by vi editor

          Other Commands

          ct catcs > filename        Copy your config spec to a file

          ct setcs filename          Set your config spec from a file

          What doew config spec say ? For example:

          element* CHECKEDOUT

          element* .../ISGcq00123456/LASTEST

          element* BLUETOOTH_00.07.00

          element* AP_SIPC.01.32.00

          element* AP_IB2.00.38_ARM

          element* /main/LATEST

          Command

          element <file path> <version path>

          file path: hello.c, *, /vob/su_java/...

          version path: Label or Branch

          4. Now you may have a task to do. You have a CR assigned, and you know the baseline version.

          • Set config spec to the baseline version.
          • Create branch type associated with the CR.

          ct mkbrtype ISGcq00123456

          • Make branch on the baseline version

          ct mkbranch ISGcq00123456 hello.c@@/main/2

             Result: hello.c@@/main/ISGcq00123456/0 is created and checked out(a copy of hello.c in the dir was created and you can edited it. If there is not hello.c in the dir, the clearcase would submit a error).

          • Add a rule to pick up this branch in the config spec, just below the CHECKEDOUT rule.

          element* .../ISGcq00123456/LATEST

          Accessional:

          • Branch type shall have naming convention designed by every project.
          • Don't want check out:

          ct mkbranch -nco ISGcq00123456 hello.c@@/main/2

          • Remove a branch from an element:

          ct rmbranch hello.c@@/main/ISGcq00123456.

             Make sure no checked out version on this branch

          • Rename a branch name

          ct rename brtype:old_name brtype:new_name

             It will apply to all the created branch.

          • Remove a branch type as well as all the related element branch

          ct rmtype -rmall brtype:ISGcq00123456

          5. After making your CR branch on the file to be changed, check out the version if it hasn't been checked out(checkout后會(huì)產(chǎn)生一個(gè)自己的私有文件,你可以自己修改,別人看不到,只有這個(gè)文件被checkin后才會(huì)放到vobs里).

          ct co -nc hello.c@@/main/ISGcq00123456/0

              Then, you are able to edit this file. After you finish the change, check in the file to vob.

          ct ci -nc hello.c

              The result is, the element will increase one version on the branch:

          hello.c@@/main/ISGcq00123456/1

          Accessional
          • A checked out version is only in your view. Other engineer can not see it. If you remove that view, you will lost the checked out version.
          • You can undo checkout by:

          ct unco hello.c

          • If a checked version has no change, it can't be checked in. You will get an error message like "The file is identical"
          • An unreserved checked out will not block other people check out the same version. Normally, we just use reserved checkout.
          • You can only check out a file on the branch which has mastership role.
          6. If your task is to create a new file, you need to do below steps:
          • Make branch on the directory that you will add the file to

          ct mkbranch ISGcq00123456 /vob/su_jave/code/src

          • The directory will be automatically checked out. Then make element in this dir.

          ct mkelem -nco hello.c

               Create a folder

          ct mkelem -eltype directory test

                Dont check it out, because you need to make the CR branch on this file.

          ct mkbranch ISGcq00123456 hello.c

          • Check in this directory. Otherwise, other people can not see your new file.

          ct ci -nc /vob/su_java/code/src

          Accessional

          • We usually only check in the file, but forget to check in the directory. This will cause the file you created can't be stored in the VOB and can't be seen by other people.
          • Go to the top project folder, use below command to list all checked out files and directories int the current dir and sub dir in your view. It will help you check in all elements.

          ct lsco -cview -r

          7. Now, your task is ongoing. In coding and testing, you may need to merge your file to other version. below example gives the merge steps:

          Example: Merge file from hello.c@@/main/branchfrom/5 to hello.c@@/main/branchto/2

          ct co -nc hello.c@@/main/branchto/2

          ct merge -to hello.c hello.c@@/main/branchfrom/5

               Usually you may also need to compare two versions

          ct diff hello.c hello.c hello.c@@/main/branchfrom/5 hello.c@@/main/branchto/2

               Compare this version from the previous version

          ct diff -pre hello.c@@/main/branchto/2

          Accessional

          • Use this command to list all versions of an element

          ct lsvt hello.c

               include the merge info

          ct lsvt -merge hello.c

               Remove a merge arrow:

          ct rmmerge hello.c@@/main/branchfrom/5 hello.c@@/main/branchto/2

               Dont do actual merge, just draw a merge line

          ct merge -ndata hello.c@@/main/branchfrom/5 hello.c@@/main/branchto/2

          In what cases we need merge:

          • Integrate with the code developed by someone else.
          • If baseline version has been incresed, need upermage.
          • Merge for release.

          8. If you want to remove an un-use version, use the command

          ct rmver hello.c@@/main/branchto/2

               Then the version 2 will be removed, but next time the version will increase from 1 to 3.

               If you want to remove a file, you can use remove name command:

          ct rmname hello.c

               Be sure to make branch and check out the current directory before rmove it, just like the steps of make element.

               If you want to rename a file, you can use

          ct mv old_name new_name

              

               If you want to create an element link, you can use

          ct ln source_file file_link

               (checkout current folder like above)

          9. Now you may have completed the task of coding, testing, inspection, and prepare to release it. You need to check your developed version is complied with below rules:

          • Must make branch from the baseline version.
          • Must have up merged your branch if the baseline version is not the LATEST version.
          • All the files and directories have no checkou.

          10. How to label the version

               Make the label type:

          ct mklbtype BLUETOOTH_00.07.00

               Make label on a version:

          ct mklabel BLUETOOTH_00.07.00 hello.c@@/main/branchto/2

               Move a label from the old version to a new version:

          ct mklabel -replace BLUETOOTH_00.07.00 hello.c@@/main/branchto/3

               Remove label on a version:

          ct rmlabel BLUETOOTH_00.07.00 hello.c@@/main/branchto/3

               Remove the label type

          ct rmtype lbtype:BLUETOOTH_00.07.00

          11. How to search the reuqired version

               Find all files with the version(.../ISGcq00373766/LATEST) and with no label SAMBA_AP_DSL_BLUETOOTH_00.00.07:

          ct find /vob/directory -version 'version(.../ISGcq00373766/LATEST)  && !version(SAMBA_AP_DSL_BLUETOOTH_00.00.07)' -print

               Find all files with the version SAMBA_AP_DSL_BLUETOOTH_00.00.07, and then search STRING in all found files:

          ct find .-version 'version(SAMBA_AP_DSL_BLUETOOTH_00.00.07)' -exec 'grep STRING $CLEARCASE_PN'

          posted @ 2008-11-12 14:14 九寶 閱讀(1239) | 評(píng)論 (0)編輯 收藏

          cramfs文件系統(tǒng)(轉(zhuǎn))

          1、cramfs的特點(diǎn)

          在嵌入式的環(huán)境之下,內(nèi)存和外存資源都需要節(jié)約使用。如果使用RAMDISK方式來使用文件系統(tǒng),那么在系統(tǒng)運(yùn)行之后,首先要把外存(Flash)上的映像文件解壓縮到內(nèi)存中,構(gòu)造起RAMDISK環(huán)境,才可以開始運(yùn)行程序。但是它也有很致命的弱點(diǎn)。在正常情況下,同樣的代碼不僅在外存中占據(jù)了空間(以壓縮后的形式存在),而且還在內(nèi)存中占用了更大的空間(以解壓縮之后的形式存在),這違背了嵌入式環(huán)境下盡量節(jié)省資源的要求。

          使用cramfs就是一種解決這個(gè)問題的方式。cramfs是一個(gè)壓縮式的文件系統(tǒng),它并不需要一次性地將文件系統(tǒng)中的所有內(nèi)容都解壓縮到內(nèi)存之中,而只是在系統(tǒng)需要訪問某個(gè)位置的數(shù)據(jù)的時(shí)侯,馬上計(jì)算出該數(shù)據(jù)在cramfs中的位置,將其實(shí)時(shí)地解壓縮到內(nèi)存之中,然后通過對(duì)內(nèi)存的訪問來獲取文件系統(tǒng)中需要讀取的數(shù)據(jù)。cramfs中的解壓縮以及解壓縮之后的內(nèi)存中數(shù)據(jù)存放位置都是由cramfs文件系統(tǒng)本身進(jìn)行維護(hù)的,用戶并不需要了解具體的實(shí)現(xiàn)過程,因此這種方式增強(qiáng)了透明度,對(duì)開發(fā)人員來說,既方便,又節(jié)省了存儲(chǔ)空間。

          cramfs擁有以下一些特性:

          采用實(shí)時(shí)解壓縮方式,但解壓縮的時(shí)侯有延遲。

          cramfs的數(shù)據(jù)都是經(jīng)過處理、打包的,對(duì)其進(jìn)先寫操作有一定困難。所以cramfs不支持寫操作,這個(gè)特性剛好適合嵌入式應(yīng)用中使用Flash存儲(chǔ)文件系統(tǒng)的場合。

          在cramfs中,文件最大不能超過16MB。

          支持組標(biāo)識(shí)(gid),但是mkcramfs只將gid的低8位保存下來,因此只有這8位是有效的。

          支持硬鏈接。但是cramfs并沒有完全處理好,硬鏈接的文件屬性中,鏈接數(shù)仍然為1.

          cramfs的目錄中,沒有“.”和“..”這兩項(xiàng)。因此,cramfs中的目錄的鏈接數(shù)通常也僅有一個(gè)。

          cramfs中,不會(huì)保存文件的時(shí)間戳(timestamps)信息。當(dāng)然,正在使用的文件由于inode保存在內(nèi)存中,因此其時(shí)間可以暫時(shí)地變更為最新時(shí)間,但是不會(huì)保存到cramfs文件系統(tǒng)中去。

          當(dāng)前版本的cramfs只支持PAGE_CACHE_SIZE為4096的內(nèi)核。因此,如果發(fā)現(xiàn)cramfs不能正常讀寫的時(shí)侯,可以檢查一下內(nèi)核的參數(shù)設(shè)置。


          2、使用cramfs

          可以從
          http://sourceforge.net/projects/cramfs/下載cramfs-1.1.tar.gz。然后執(zhí)行

          tar zxvf cramfs-1.1.tar.gz

          進(jìn)入解包之后生成cramfs-1.1目錄,執(zhí)行編譯命令:

          make

          編譯完成之后,會(huì)生成mkcramfs和cramfsck兩個(gè)工具,其中cramfsck工具是用來創(chuàng)建cramfs文件系統(tǒng)的,而mkcramfs工具則用來進(jìn)行cramfs文件系統(tǒng)的釋放以及檢查。

          下面是mkcramfs的命令格式:

          mkcramfs [-h] [-e edition] [-i file] [-n name] dirname outfile

          mkcramfs的各個(gè)參數(shù)解釋如下:

          -h:顯示幫助信息

          -e edition:設(shè)置生成的文件系統(tǒng)中的版本號(hào)

          -i file:將一個(gè)文件映像插入這個(gè)文件系統(tǒng)之中(只能在Linux2.4.0以后的內(nèi)核版本中使用)

          -n name:設(shè)定cramfs文件系統(tǒng)的名字

          dirname:指明需要被壓縮的整個(gè)目錄樹

          outfile:最終輸出的文件


          cramfsck的命令格式:

          cramfsck [-hv] [-x dir] file

          cramfsck的各個(gè)參數(shù)解釋如下:

          -h:顯示幫助信息

          -x dir:釋放文件到dir所指出的目錄中

          -v:輸出信息更加詳細(xì)

          file:希望測(cè)試的目標(biāo)文件

          posted @ 2008-08-14 15:43 九寶 閱讀(504) | 評(píng)論 (0)編輯 收藏

          linux創(chuàng)建2種新文件方式

          linux下沒有文件后綴來比較文件格式的用法
          只有兩種文件基于文本格式的sh和可以執(zhí)行的2進(jìn)制文件

          vi filename
          在編輯好你的文件后可以用wq!保存
          這樣就可以生成一個(gè)你以編輯好的文件
          還有vim gedit等文件編輯器
          也可以用上樓說的生成一個(gè)文件

          touch filename

          posted @ 2008-07-10 15:50 九寶 閱讀(266) | 評(píng)論 (0)編輯 收藏

          Bash Shell-使用內(nèi)置的set和shopt命令設(shè)置bash選項(xiàng)

          set -o 打印所以的選項(xiàng)
          set -o vi 打開選項(xiàng)
          set +o vi 關(guān)閉選項(xiàng)

          shopt -p 打印所以的選項(xiàng)
          shopt -s cdspell打開選項(xiàng)
          shopt -u cdspell關(guān)閉選項(xiàng)

          posted @ 2008-07-10 15:49 九寶 閱讀(280) | 評(píng)論 (0)編輯 收藏

          Shell 運(yùn)算和進(jìn)制轉(zhuǎn)換(轉(zhuǎn))

          Shell 運(yùn)算和進(jìn)制轉(zhuǎn)換

          Shell 提供大量的基本運(yùn)算操作,在腳本中非常有用。Shell 對(duì)您提供的算術(shù)表達(dá)式求值,執(zhí)行運(yùn)算展開式,此時(shí)使用得出的結(jié)果替換表達(dá)式。以下面的格式提供運(yùn)算表達(dá)式:

          $(( expression ))
                                  

          您可以使用 echo 在命令行顯示運(yùn)算展開式的結(jié)果,了解其工作情況?,F(xiàn)在嘗試清單 5 所顯示的結(jié)果。


          清單 5. Bourne Shell 中的運(yùn)算展開式
                               
                                  $ echo $((10+40))
                                  50
                                  $ echo $((5*(3+3)))
                                  30
                                  

          您還可以將展開式分配給變量。嘗試清單 6 所顯示的結(jié)果。


          清單 6. 將運(yùn)算展開式分配給 Shell 變量
                               
                                  $ myvar = 10
                                  $ echo $myvar
                                  10
                                  $ echo $(($myvar-2))
                                  8
                                  $ myvar = $(($myvar+5))
                                  $ echo $myvar
                                  15
                                  $ result = $(($myvar-10))
                                  $ echo $result
                                  5
                                  $
                                  

          表 2 列出了在大多數(shù) Bourne 以及與 Bourne 兼容的 Shell中可以使用的運(yùn)算符。正如上面第二個(gè)示例,使用圓括號(hào)括起來的語句有更高的優(yōu)先級(jí)。實(shí)際上,Shell 算術(shù)優(yōu)先級(jí)通常根據(jù) C 語言的規(guī)則來確定。


          表 2. Shell 條件表達(dá)式
          運(yùn)算符 描述
          +
          -
          *
          /
          % 求余
          < 小于(1 代表真,0 代表假)
          <= 小于等于(1 代表真,0 代表假)
          > 大于(1 代表真,0 代表假)
          >= 大于等于(1 代表真,0 代表假)
          << 按位向左移位:將給定的整數(shù)或第一個(gè)表達(dá)式向左移動(dòng)第二個(gè)表達(dá)式表示的位數(shù)
          >> 按位向右移位:將給定的整數(shù)或第一個(gè)表達(dá)式向右移動(dòng)第二個(gè)表達(dá)式表示的位數(shù)




          回頁首


          使用 Shell 運(yùn)算進(jìn)行進(jìn)制轉(zhuǎn)換

          假定在您的腳本中有一些數(shù)字,您需要以另外的進(jìn)制處理這些數(shù)字。使用 Shell 運(yùn)算可以很容易地自動(dòng)實(shí)現(xiàn)這類轉(zhuǎn)換。一種情況是使用 Shell 運(yùn)算把一個(gè)數(shù)字從給定的進(jìn)制轉(zhuǎn)換位十進(jìn)制。如果數(shù)字以運(yùn)算展開式的形式提供,那么假定它帶有十進(jìn)制符號(hào),除非 它前面帶有 0(這種情況假定是八進(jìn)制)或 0x(這種情況假定是十六進(jìn)制)。鍵入以下內(nèi)容以得到一些八進(jìn)制和十六進(jìn)制值的十進(jìn)制輸出:

          $ echo $((013))
                                  $ echo $((0xA4))
                                                  

          您還可以使用以下格式指定 2 到 64 之間的任意進(jìn)制:

          $((BASE#NUMBER))
                                  

          通過在 Shell 提示符后鍵入清單 7 中所示的行,嘗試將二進(jìn)制、八進(jìn)制、十六進(jìn)制以及其他進(jìn)制的數(shù)轉(zhuǎn)換為十進(jìn)制。


          清單 7. 在 Shell 中將任意進(jìn)制的數(shù)以十進(jìn)制輸出
                               
                                  echo $((2#1101010))
                                  echo $((8#377))
                                  echo $((16#D8))
                                  echo $((12#10))
                                  echo $((36#ZZYY))
                                  

          使用 bc 進(jìn)行進(jìn)制轉(zhuǎn)換

          在 Shell 中進(jìn)行進(jìn)制轉(zhuǎn)換的另一個(gè)訣竅是使用 bc,它是一種任意精度運(yùn)算語言,大多數(shù) UNIX 安裝程序都提供。因?yàn)樗试S您指定輸出進(jìn)制,所以當(dāng)您需要以十進(jìn)制以外的進(jìn)制輸出時(shí),這是一種很好的技術(shù)。

          bc 的特殊變量 ibaseobase 分別包含用于輸入和輸出的進(jìn)制的值。缺省情況下,都被設(shè)置為 10。要執(zhí)行進(jìn)制轉(zhuǎn)換,需要改變其中的一個(gè)或兩個(gè)值,然后提供一個(gè)數(shù)字。立即嘗試,如清單 8 中所示。


          清單 8. 使用 bc 執(zhí)行進(jìn)制轉(zhuǎn)換
                               
                                  $ bc -ql
                                                      10
                                  10
                                  obase=16
                                                      10
                                  A
                                  ibase=2
                                                      10
                                  2
                                  
                                                           Control-D
                                                      
                                  $
                                  

          要快速執(zhí)行進(jìn)制轉(zhuǎn)換,可以聯(lián)合使用 bcecho形成快捷的單命令行程序,將給定的值通過管道傳輸給 bc。鍵入清單 9 中顯示的內(nèi)容。


          清單 9. Shell 單命令行 bc 程序
                               
                                  $ echo 'obase=16; 47' | bc
                                  2F
                                  $ echo 'obase=10; ibase=16; A03' | bc
                                  2563
                                  $
                                  

          警告:當(dāng)您設(shè)置 bc 的輸入進(jìn)制以后,輸入 bc 的所有數(shù)字都使用該進(jìn)制,包括您提供用于設(shè)置輸出進(jìn)制的數(shù)字。因此最好先設(shè)置輸出進(jìn)制,否則可能會(huì)產(chǎn)生意想不到的結(jié)果,如清單 10 中所示。


          清單 10. 設(shè)置輸入和輸出進(jìn)制的先后順序的重要性
                               
                                  $ echo 'ibase=16; obase=10; A' | bc
                                  A
                                  $ echo 'ibase=16; obase=A; A' | bc
                                  10
                                  $
                                  

          posted @ 2008-07-09 14:46 九寶 閱讀(1654) | 評(píng)論 (0)編輯 收藏

          執(zhí)行shell程序文件有4種方法(轉(zhuǎn))

          執(zhí)行shell程序文件有4種方法
            (1)#chmod +x file(在/etc/profile中,加入export PATH=${PATH}:~/yourpath,就可以在命令行下直接運(yùn)行,像執(zhí)行普通命令一樣)
            (2)#sh file
            (3)# . file
            (4)#source file

          posted @ 2008-07-08 10:21 九寶 閱讀(206) | 評(píng)論 (0)編輯 收藏

          Bitwise operators and Shift operators

          位運(yùn)算符與邏輯運(yùn)算符基本相似,不過后者的對(duì)象只是表示真和假的二值運(yùn)算,位運(yùn)算符的對(duì)象則是二進(jìn)制數(shù)。Java語言中字節(jié)、字符和整數(shù)等都可以轉(zhuǎn)換為二進(jìn)制,所以位運(yùn)算符的對(duì)象也可以是它們。常見位運(yùn)算符有:
          按位進(jìn)行與運(yùn)算 : &
          按位進(jìn)行或運(yùn)算 : |
          按位進(jìn)行位異運(yùn)算: ^
          按位進(jìn)行取反運(yùn)算: ~
          按位進(jìn)行循環(huán)左移:<<,運(yùn)算符左側(cè)對(duì)象左移由右側(cè)指定的位數(shù),低位補(bǔ)0,最高位拋棄。帶符號(hào)的左移位運(yùn)算相當(dāng)于對(duì)左操作數(shù)進(jìn)行乘2運(yùn)算。
          按位進(jìn)行循環(huán)右移:>>,運(yùn)算符左側(cè)對(duì)象右移由右側(cè)指定的位數(shù),若值為正,在最高位插入0,若值為負(fù),在最高位插入1,即移入的最高位和原最高符號(hào)位相同。帶符號(hào)的右移位運(yùn)算相當(dāng)于對(duì)左邊的運(yùn)算對(duì)象進(jìn)行除2運(yùn)算。
          按位進(jìn)行無符號(hào)右移:>>>,無論運(yùn)算符左邊的運(yùn)算對(duì)象取值正負(fù),都在高位插入0,即移入位始終補(bǔ)0.
          要注意是沒有按位進(jìn)行無符號(hào)左移的。位運(yùn)算符的操作數(shù)只能是整數(shù),char,byte,short,
          int和long,進(jìn)行位運(yùn)算時(shí),總是先將字符型值、字節(jié)型值和短整型值轉(zhuǎn)換為整型再進(jìn)行位運(yùn)算。位運(yùn)算符游標(biāo)的操作數(shù)用于指定移動(dòng)的位數(shù),按規(guī)定其不應(yīng)超過左側(cè)數(shù)的進(jìn)制表示位數(shù)。
          The bitwise operators allow you to manipulate individual bits in an integral primitive data type.Bitwise operators perform Boolean algebra on the corresponding bits in the two arguments to produce the result. The bitwise operators come from C’s low-level orientation, where you often manipulate hardware
          directly and must set the bits in hardware registers. Java was originally designed to be embedded in TV set-top boxes, so this low-level orientation still made sense. However, you probably won’t use the bitwise operators much.
          The bitwise AND operator (&) produces a one in the output bit if both input bits are one; otherwise, it produces a zero.
          The bitwise OR operator (|) produces a one in the output bit if either input bit is a one and produces a zero only if both input bits are zero.
          The bitwise EXCLUSIVE OR, or XOR (^), produces a one in the output bit if one or the other input bit is a one, but not both.
          The bitwise NOT (~, also called the ones complement operator) is a unary operator; it takes only one argument. (All other bitwise operators are binary operators.) Bitwise NOT produces the opposite of the input bit—a one if the input bit is zero, a zero if the input bit is one.

          posted @ 2008-05-20 13:22 九寶 閱讀(382) | 評(píng)論 (0)編輯 收藏

          僅列出標(biāo)題
          共9頁: 上一頁 1 2 3 4 5 6 7 8 9 下一頁 
          主站蜘蛛池模板: 三穗县| 云南省| 镇远县| 潞城市| 渝中区| 石狮市| 甘谷县| 乐东| 永吉县| 蛟河市| 洛宁县| 东乡县| 山东省| 周宁县| 台州市| 安庆市| 江都市| 瓦房店市| 泰宁县| 滦南县| 留坝县| 衡阳市| 杨浦区| 资阳市| 象山县| 花垣县| 佛教| 波密县| 桐庐县| 彭山县| 囊谦县| 浙江省| 监利县| 六盘水市| 英超| 河间市| 延庆县| 霸州市| 通辽市| 清水河县| 公主岭市|