Oro igo? · bei.pm
Na dispela hap, i gat ol artikel long ol file format na reverse engineering.
Na nau, i olsem:
I gat planti programing languag long autsait na planti pipol i save ol samting long narapela nem - o i no gat wanpela klia long ol samting we i bikpela tru, bikos ol programing languag i no lukim ol samting.
tl;dr:
Naikim naipela notesen i go long C99 <stdint.h>
. Ol man i save long dispela notesen, bai ol i gut long kisim dispela notesen bilong mi.
Intiga
Integer em iwan iwan, em iwan olsem ol namba nogat koma.
Ol Integer em i stap long ol data format long wanpela spesifik namba rang, olsem wanpela resoluson. Mi givim dispela long Bit - long dispela rason, em "Byte" na ol tipe we i kamap long en (Word, Qword, ...) em i mas stap long platform.
Na tu, long Integer tipe, mipela i makim tu natural namba (ℕ, em i no gat signe - Unsigned) na full namba (ℤ, em i gat signe - Signed).
Dispela info i kamap long wanpela signe long name (u
o s
).
Em i posib long signe bilong full namba i kamap olsem wanpela komplement o olsem tupela komplement.
Sapos i no gat narapela mak, tupela komplement i yusim, long wanem, em i stap long modern komputer wok olsem wanpela bikpela we i yusim.
Mi yusim ol namba nogat signe long ol dokumen bilong mi olsem uint
, na i makim kangu bilong en long Bits.
Ol namba we i gat signe, mi yusim long ol dokumen bilong mi olsem sint
, na tu i makim kangu bilong en long Bits.
Mi no yusim ol datatype "char" long ol saien, long wanem, ol saien strin i mas stap olsem ol Integer namba strin long wanpela spesifik interpretasyon.
Dispela i kamap olsem uint(8)[].
Ol eksampel:
Notation | C99 stdint.h -Wokai |
Deskripsin | Numba Ruma |
---|---|---|---|
uint(16) | uint16_t | Unsigned Integer, 16 Bit Lenght | 0 - 65.535 |
sint(8) | int8_t | Signed Integer, 8 Bit Lenght, Two's Komplement | -126 - 127 |
uint(24) | uint32_t:24 | Unsigned Integer, 24 Bit Lenght | 0 - 16.777.216 |
Festkomma-wei
Fixed-point values emi ol valu bilong Rational numbers (Q), olsem na i gat komma na komma plenti.
Long fixed-point values, - olsem na nem - posisen bilong koma i stap olsem datatypes.
Olsem na, i gat wanpela fixed range bilong ol valu bilong dispela datatype; matematikally, displa valu i finait.
Long trutru, dispela datatype i mostly yusim long ol platform we i no gat fast floating-point hardware, long wanem, calculation bilong fixed-point values i ken kamap long integer units.
Olsem na, dispela datatype i yusim long ol database management systems, sapos fixed requirements i mas i kamap.
Thinkim long ol sistem long permanent storage bilong financial data; most currencies i gat limit long 2 plenti bihain koma.
(I no gut long yusim fixed-point values; em i gut moa long save smallest currency unit olsem integer na save long narapela display level)
Olsem long integer values, mi givim resolution bilong valu bifor na bihain koma:
ufixed(9,7)
i makim wan datatype, we i no gat sign, we i reservim 9 bits bilong value bihain koma, na 7 bits bilong value bihain koma; long olgeta, i 16 bits wide na olsem na i ken coverim area bilong (0,0) go long (511,127) olsem wan vector bilong tupela independent integers.
Displa interpretation bai olsem na long decimal representation i lusim 28 values, long wanem, i likim long maximum (511,99) long praktik.
Instead bilong wan direct interpretation bilong fixed-point value olsem wan vector bilong 2 separate integers - we em i minim olsem na i gat wan unused data area long conversion long decimal numbers na manual transfer - i ken yusim na bihain koma area olsem fraction bilong olgeta resolution.
Long example bilong ufixed(9,7)
, i kamap wan fraction long denominator bilong 27 - displa value i go long 0.00 go long 511 + 126⁄127
For conversion long wan decimal representation, bihain koma plenti mas i dividim long 128.
Long dispela way, i isi long mekim calculation, long wanem, transfer i kamap automatically, olsem na dispela way i prefer long ol man.
Dispela way i gat wan disadvantage, long wanem, bihain koma plenti long decimal representation i no gat guaranteed resolution, wan single decimal place i no moa gat value 0.01
, tasol em i gat 0.007874
, we bai kamapim rounding errors.
We i yusim interpretation, i mas dokument long ples we i yusim.
Wanta floskomma o wanta gletkomma
Fließkomma-Werte emi matematikal komples expreshen, bipo wan bigpela namba wantaim stabil rezolusen i olsem expreshim, olsem na ol dekli namba i kamap long sainifik noteshon.
Ol most komon wei bilong mekim dispela i bin stanap long IEEE 754 na em i bin aknoledgim long ol nara kantri.
Fließkomma-Wert i gat ol nait bilong ol komponent:
Sign (0 o 1 ) |
Exponent | Mantisse |
Waile sign i bin asim olsem binari Yes/No, tru namba i kamap long ekweishen
Mantisse * 2Exponent
Mo, i gat wanpela ranga konstant ol namba, i kaverim spesel kes rational namba - long en i gat ±∞
na NaN
("namba i no inap").
Fließkomma-Werte i gat bikpela yus, sapos ol prisen i no bikpela importens, bikos long dispela wei, i mas kamap ol raonding misteks na olsem na ol prisen i no stap gut. Ol i yusim Fließkomma-Werte long defenim koorinets, olsem vertex-vectors long 3D-models o Bézier/Spline-kurves long optikal reprensentashon.
Long ol data format, Fließkomma-Werte i bin spesifai olsem float(Mantisse, Exponent)
.
Sapos wanpela format i no olsem IEEE 754, dispela bai i tokim gut.