密碼學筆記
  • Introduction
  • 數論相關
  • 大數轉換
  • Big Endian & small Endian
  • MD5
  • RSA
  • DSA
  • AES
  • SHA256
  • RIPEMD
  • ECDSA & ECDH
  • OpenSSL 實用指令
  • Crypto module
  • Byte Padding
Powered by GitBook
On this page

Was this helpful?

Big Endian & small Endian

0x12345678:

Small Endian: 0x78 0x56 0x34 0x12 


Big Endian: 0x12 0x34 0x56 0x78

以下為範例程式(BigEndian_to_SmallEndian)

function BigEndian_to_SmallEndian(hexNum) {
  let SmallEndian_array = [];
  if (hexNum.length % 2 !== 0) {
    hexNum = '0' + hexNum // 數字總數為奇數的話 在開頭補0
  }

  for (let i = 0, len = hexNum.length; i < len; i++) {
    if (i % 2 !== 0) {
      SmallEndian_array.unshift(hexNum.charAt(i - 1) + hexNum.charAt(i))
    }
  }

  return SmallEndian_array.join('');
}

如果要把Smail 轉為BIg Endian則為同一個程式,把數字再放入跑一次即可轉回

Previous大數轉換NextMD5

Last updated 5 years ago

Was this helpful?