Devdit
 

Python int to bytes ด้วยคำสั่ง to_bytes

1K

สอนเขียนภาษา Python เพื่อแปลง int to bytes ด้วยคำสั่ง to_bytes โดยคำสั่งนี้จะมีการกำหรด argument 2 ค่า คือ length และ byteorder สามารถเขียนโปรแกรมได้ดังนี้

 

ตัวอย่าง Python int to bytes ด้วยคำสั่ง to_bytes

i = 30
print( type(i), i )
i = i.to_bytes( 2, byteorder='big' )
print( type(i), i )

ผลลัพธ์

<class 'int'> 30
<class 'bytes'> b'\x00\x1e'
เขียน 2 ปีที่แล้ว
ชอบ
ลิ้งก์
แชร์
Devdit มีช่อง YouTube แล้ว
เราสร้างวิดีโอเกี่ยวกับเทคโนโลยี ทำตามง่ายๆ