လက်ရှိတည်နေရာ: ပင်မစာမျက်နှာ> နောက်ဆုံးရဆောင်းပါးများစာရင်း> PHP's Bindec () Bindecer_Convert () လုပ်ဆောင်ချက်များကို အသုံးပြု. Binary နံပါတ်များကို Hexadecimal သို့မည်သို့ပြောင်းလဲရမည်နည်း။

PHP's Bindec () Bindecer_Convert () လုပ်ဆောင်ချက်များကို အသုံးပြု. Binary နံပါတ်များကို Hexadecimal သို့မည်သို့ပြောင်းလဲရမည်နည်း။

M66 2025-06-15

နောက်ခံအချက်အလက်များသို့မဟုတ်ကွန်ယက်ပရိုဂရမ်းမင်းများကိုပြုပြင်သည့်အခါ Binary နှင့် Hexadecimal အကြားပြောင်းလဲရန်လိုအပ်ချက်ကိုကျွန်ုပ်တို့မကြာခဏကြုံတွေ့ရလေ့ရှိသည်။ ကံကောင်းထောက်မစွာပင် PHP သည်ဤလုပ်ငန်းကိုပြီးမြောက်အောင်မြင်စေရန်ရိုးရိုးရှင်းရှင်းသုံးရန်လွယ်ကူသောလုပ်ဆောင်မှုများကိုထောက်ပံ့ပေးသည်။ အသုံးအများဆုံးအသုံးပြုသူများမှာ bindec () နှင့် base_convert ()

1 ။ Control to bindec () + dechex () ကိုသုံးပါ

Bindec () သည် PHP တွင်binသော function တစ်ခုဖြစ်သည်။ Dechelex () သည် ဒ decimal မကိန်းများကို hexadecimal strings သို့ပြောင်းလဲနိုင်သည်။ ဤလုပ်ဆောင်ချက်နှစ်ခုကိုပေါင်းစပ်ပြီးကျွန်ုပ်တို့သည် Hexadecimal ပြောင်းလဲခြင်းသို့ binary ကိုဖြည့်စွက်နိုင်သည်။

နမူနာကုဒ်:

<Code> $ binary = '11010110', $ decimal = bindec ($ binary); // ဒ decimal မ $ hex = dechex ($ ဒ decimal မ) // hex echo strutoupper ($ hex) သို့ပြောင်းရန်; // output: d6 </ code>:

ဤဥပမာတွင် 11010110 ကို ဒ decimal မကိန်းတွင် 214 သို့ပြောင်းလဲပြီး Hexadecimal တွင် D6 သို့ကူးပြောင်းသည်။

2 ။ basebertert () စစ်ဆင်ရေးကိုရိုးရှင်းစေရန်

အကယ်. သင်သည်ဒ decimal မကိုပထမဆုံးလှည့်ရန်အခုန်းအရာဟုသင်ထင်လျှင်၎င်းသည် Hexadecimal နှင့် Hexadecimal, PHP ၏ Base_Convert () သည် ပိုမိုတိုက်ရိုက်နည်းလမ်းကိုပေးသည်ဟုသင်ထင်လျှင် ဤလုပ်ဆောင်မှုသည်ကျွန်ုပ်တို့အားအရင်းအမြစ် Cardinalusalusality နှင့် Target Cardinality ကိုတိုက်ရိုက်သတ်မှတ်ရန်ခွင့်ပြုသည်။

နမူနာကုဒ်:

<Code> $ binary = '11010110', $ hex = base_convert ($ binary, 2, 16); ပဲ့တင်သံ strutoupper ($ hex); // output: d6 </ code>:

ဤလုပ်ဆောင်ချက်၏ပထမဆုံး pareter သည်ပြောင်းလဲရန် string ကိုပြောင်းလဲရန် string ကိုဆိုလိုသည်။ ဒုတိယ parameter သည်မူလ binary ဖြစ်သည်။ တတိယအချက်မှာ Tark Binary ဖြစ်သည်။

3 ။ မှတ်စုဖို့အရာ

  1. လွန်ခဲ့သည့် Binary string သည် တရား 0 င် Binary Number (1 နှင့် 1 အပါအ 0 င်) ဖြစ်ရမည်

  2. Base_Convert () ကို အသုံးပြုသောအခါ, ပြန်လာတန်ဖိုးသည် string type ဖြစ်သည်။ အကယ်. Hexadecimal နံပါတ်သည်အခြား binary နံပါတ်များအကြား ဆက်. ပြောင်းလဲရန်လိုအပ်ပါကပြောင်းလဲခြင်းကိုသင်အာရုံစိုက်သင့်သည်။

  3. အကယ်. သင်သည်ဂဏန်းအရေအတွက်ကိုဖြည့်ရန်လိုအပ်ပါက strow_pad () function ကိုသုံးနိုင်သည်။ ဥပမာအားဖြင့် 2-bit hexadecimalum နံပါတ်ကိုအမြဲတမ်းထုတ်လုပ်ရန်သင်ဤကဲ့သို့သောရေးနိုင်သည်။

<code> $ hex = strtoupper (strt_pad (strow_convert (base_converter), 2, 16, 16, 16, 16, 2, '0 င်' 0 ', // output: 0D </ code>

IV ။ လျှောက်လွှာဇာတ်လမ်းတစ်ပုဒ်

Network Data Packets များ, Bitmap Data ကဲ့သို့သောအခြေအနေများ,

<code> $ ဒေတာ = ['11000011', '10101010', '11110000']; foreach ($ data $ binary အဖြစ်) {echo strutoupper (base_convert ($ binary, 2, 16)) ။ " } // output: c3 aa f0 </ code>

ရလဒ်ကို hexadecimal color တစ်ခုအနေဖြင့်လည်းထုတ်ယူနိုင်သည်။

<Code> $ R = '11110000'; $ g = '10101010'; $ ခ = '' 11000011 '; $ hexcolor = '#' ။ strutoupper (base_convert ($ R, 2, 16)) ။ Strtoupper (base_converter ($ g, 2, 16)) ။ strutoupper (base_converter ($ ခ, 2, 16)); ECHO $ ​​hexcolor; // output: # f0aac3 </ code> #

5 ။ လက်တွေ့အသုံးချမှုများ - M66.NET မှအချက်အလက်များကိုလုပ်ဆောင်ခြင်း

အကယ်. သင်သည် binary encoded data တစ်ခုမှဝေးလံခေါင်သီသော interface မှအပိုင်းအစတစ်ခုရရှိပါကဥပမာ -

<Code> $ Response = file_get_contents (https://m66.net/api/api/pi/data/binary '); $ ဒေတာ = JSONS_DECODE ($ တုံ့ပြန်မှု, စစ်မှန်သော); // ပြန်လာပြီဟုယူဆပါက '111110000', '11110000'] foreach ($ ဒေတာ) ($ binary) {echo strutoupper (base_convert ($ binary, 2, 16)) ။ " } // output: cc f0 </ code>

File_get_Contents () , JSON_Decode () နှင့် base_convert () ကိုပေါင်းစပ်ခြင်းဖြင့် Binary Data ကိုမြန်မြန်ဆန်ဆန်ပြောင်းလဲခြင်းနှင့်ပြသရန်အတွက်ဖတ်နိုင်သော Hexadecimalial format ဖြင့်လျင်မြန်စွာပြောင်းလဲနိုင်သည်။