[Python] [Ruby] hex string(16진수 문자열)의 endian을 큰 endian에서 작은 단위로 변경합니다.
3148 단어 numerationSystemPythonEndian
생각
Hexstring은 두 글자로 한 바이트를 표시하기 때문에 단순히 문자열의 배열을 반대 순서로 하면 서로 다른 바이트열이 된다.str에서 bytes로 바뀐 후 반대 순서대로 순조롭게 진행될 수 있습니다.
메서드
Python
방법1
import binascii
hex_be = 'f0148c'
bytes_be = binascii.unhexlify(hex_be)
bytes_le = bytes_be[::-1]
hex_le = binascii.hexlify(bytes_le).decode()
hex_le # '8c14f0'
방법2
4@shiracamus선생님, 감사합니다.hex_be = 'f0148c'
bytes_be = bytes.fromhex(hex_be)
bytes_le = bytes_be[::-1]
hex_le = bytes_le.hex()
hex_le # '8c14f0'
Ruby
hex_be = 'f0148c'
bytes_be = Array(hex_be).pack('H*')
bytes_le = bytes_be.reverse
hex_le = bytes_le.unpack1('H*')
hex_le # '8c14f0'
Reference
이 문제에 관하여([Python] [Ruby] hex string(16진수 문자열)의 endian을 큰 endian에서 작은 단위로 변경합니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/QUANON/items/e3d91a6f33536bd0de5a
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Python
방법1
import binascii
hex_be = 'f0148c'
bytes_be = binascii.unhexlify(hex_be)
bytes_le = bytes_be[::-1]
hex_le = binascii.hexlify(bytes_le).decode()
hex_le # '8c14f0'
방법2
4@shiracamus선생님, 감사합니다.
hex_be = 'f0148c'
bytes_be = bytes.fromhex(hex_be)
bytes_le = bytes_be[::-1]
hex_le = bytes_le.hex()
hex_le # '8c14f0'
Ruby
hex_be = 'f0148c'
bytes_be = Array(hex_be).pack('H*')
bytes_le = bytes_be.reverse
hex_le = bytes_le.unpack1('H*')
hex_le # '8c14f0'
Reference
이 문제에 관하여([Python] [Ruby] hex string(16진수 문자열)의 endian을 큰 endian에서 작은 단위로 변경합니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/QUANON/items/e3d91a6f33536bd0de5a텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)