Yuav ua li cas hloov int rau byte hauv Python?
Yuav ua li cas hloov int rau byte hauv Python?

Video: Yuav ua li cas hloov int rau byte hauv Python?

Video: Yuav ua li cas hloov int rau byte hauv Python?
Video: Data Science with Python! Analyzing File Types from Avro to Stata 2024, Kaum ib hlis
Anonim

Siv int . to_bytes() rau hloov ib mus bytes

Hu int . to_bytes(ntev, byteorder) ntawm ib int nrog xav ntev ntawm lub array li ntev thiab qhov kev txiav txim ntawm lub array li byteorder rau hloov tus mus bytes . Yog tias byteorder tau teem rau "loj", qhov kev txiav txim ntawm qhov tseem ceeb tshaj plaws bytes pib thaum pib ntawm array.

Hais txog qhov no, pes tsawg bytes yog ib qho int hauv Python?

16 bytes

Ib sab saum toj no, pes tsawg qhov me me yog int hauv Python? 32bit ib

Ua raws li qhov no, peb puas tuaj yeem hloov txoj hlua rau int hauv Python?

Cov hlua tuaj yeem hloov mus rau cov lej los ntawm kev siv lub int () thiab float() txoj kev. Yog koj txoj hlua tsis muaj decimal qhov chaw, koj ' feem ntau yuav xav tau hloov nws rau ib tus lej los ntawm kev siv lub int () txoj kev.

Peb puas tuaj yeem hloov int mus rau byte hauv Java?

Hauv Java , ib int yog 32bt. A byte yog 8bt. Feem ntau primitive hom nyob rau hauv Java tau kos npe, thiab byte , luv, int , thiab ntev yog encoded hauv ob qhov ntxiv. Yog li yog tias koj muaj byte 255: 11111111 thiab koj xav sawv cev ua ib tug int (32 ntsis) koj tsuas yog luam 1 mus rau sab laug 24 zaug.

Pom zoo: