How to swim and work in IL

When we declare a variable int, for example:

int i = 4;

The following IL is called:

IL_0001:  /* 1A   |                  */ ldc.i4.4

I can understand that 1A is a hexadecimal representation of 4, so I understand that the value of the hexadecimal value is stored to refer to its value or does it mean something else?

When I declare a double variable like:

double d = 12.34;

An IL is called that cannot get a few things in it:

IL_0003:  /* 23   | AE47E17A14AE2840 */ ldc.r8     12.34

How is 23 going and what does it mean and what is here AE47E17A14AE2840?

When I declare a float with the same value:

float f = 12.34f;

I have this IL:

IL_000d:  /* 22   | A4704541         */ ldc.r4     12.34

The same question is here, how and how it 22comes, and what does it mean, and what is it A4704541?

+4
source share
3

, , ildasm. , - .

, 1A 4, , , - ?

1A ldc.i4.4. ldc.i4 4, , 5 , 1 4 . int -1 8, , .

, . 23 22 - , - IEEE 754.

+8

IL . ldc.i4.4 - 0x1A, ldc.r8 - 0x23, ldc.r4 - 0x22. IL, .

ldc.r4 ldc.r8 , 4 8- . . A4-70-45-41 - , BitConverter.GetBytes(12.34f), , .

ldc.i4.4 , , 4 . -1 9 ​​, . IL.

+7

"AE 47 E1 7A 14 AE 28 40" is a hexadecimal representation of the actual representation of double value bytes 12.34.

To prove that

double d = 12.34;   
var bytes = BitConverter.GetBytes(d);
StringBuilder sb = new StringBuilder();
foreach (var b in bytes)
{
    sb.Append(b.ToString("X2"));
}
sb.Dump();

Print

AE47E17A14AE2840

23 is a hexadecimal representation of the value of Opcode ldc.r8and 22 for ldc.r4etc.

Source

+3
source

Source: https://habr.com/ru/post/1625316/


All Articles