Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Which unit is Delphi fillchar in?
Which unit is Delphi fillchar in?
Fillchar is the standard process of the system unit of Turbo/Borland Pascal, and its usage format is: Fillchar (var x; Count:

WordValue), its function is to assign the low count bytes occupied by the specified variable x in the memory segment to the same value.

Where value is a padding value and can only be a single-Byte value, such as byte, Char or Boolean. In Free Pascal, it is slightly extended to FillChar(var X

Count: Longint value), the function has not changed.

[Example1]: Fillchar is usually used to assign initial values to data.

defined variable

A: Array [1...10 of arr type]

Execute fillchar(a, sizeof(a), 0)

When the array type is

1.real (similar to other real numbers) makes all elements in a 0.0.

2. Integers (byte, word, longint, shortint are all the same) are all 0.

3. Boolean leave.

4. All characters are #0.

The function sizeof(a) is used here, and its function is to return the total number of bytes occupied by variable A, as shown in the above example:

When the array type is

The value of 1.realsizeof (a) is 60 (each element takes 6 bytes, and 10 elements * * * takes 60 bytes).

stove fire

The value of izeof(a) is 40 (4 bytes per element, 10 element 40 bytes * *).

double;twofold

The value of izeof(a) is 80 (8 bytes per element, 10 elements * * *, 80 bytes).

extend

The value of izeof(a) is 100 (each element accounts for 10 bytes, and 10 elements * * * accounts for 100 bytes).

com

The value of izeof(a) is 80 (8 bytes per element, 10 elements * * *, 80 bytes).

2.2. The value of 2.2.integer(word) sizeof(a (a a (a) is 20.

(Each element accounts for 2 bytes, and 10 elements * * * account for 20 bytes)

3. The value of 3.byte sizeof (a) is 10.

(Each element accounts for 1 byte, and 10 elements * * * account for 10 byte)

4. The value of longint sizeof (a) is 40 (4 bytes per element, 10 element 40 bytes * *).

5. The value of Boolean sizeof (a) is 10 (each element accounts for 1 byte, and 10 elements * * * account for1byte).

6. The value of charsizeof (a) is 10.

(Each element accounts for 1 byte, and 10 elements * * * account for 10 byte)

Therefore, the result of the example 1 is to fill all elements (all bytes) of array A with 0. It should be noted that the interpretation of "0" is completely different for different types of data! For integer or real numbers

Generally speaking, if all bytes are 0, then the number is also 0; For Boolean quantity (one byte), 0 means false (non-0 means true), then the quantity is false; Right character type

As far as the number (one byte) is concerned, 0 represents a character with an ASCII code value of 0, so the number is #0.

[Example 2]: fillchar(a, sizeof(a), 0) in the above example is changed to

Fillchar(a, sizeof(a), 1), what's the result?

Execute fillchar(a, size(a), 1).

When the array type is

1.boolean is all true (1 is a non-zero value, which means true).

2. The characters are all # 1.

3. Bytes, short integer

Each element is 1 byte, all of which are 1

4.integer, word each element has 2 bytes, all of which are (257) 10. this is because

In an integer or word variable, both the high byte and the low byte are filled with 1 (binary number 1 is converted into binary number 000000 1), and the result is:

High byte and low byte

15 14 13 12 1 1 10 9 8 | 7 6 5 4 3 2 1 0

0 0 0 0 0 0 0 1

| 0 0 0 0 0 0 0 1

Obviously, the number obtained is (257)10 = (000000100001) 2.

If Fillchar (a, size (a), 17 1) is executed, what is the result?

Because (171)10 = (1011) 2, it is:

High byte and low byte

15 14 13 12 1 1 10 9 8

| 7 6 5 4 3 2 1 0

1 0 1 0 1 0 1 1 | 1 0 1 0 1 0 1 1

For the integer type quantity, its value is (-2 1589) 10, because the integer type data is a signed number represented by its complement, the highest bit is the sign bit, and 0 represents it.

Positive, 1 means negative, because this number is negative, so its complement is101110/kloc.

1101010101,and its value is-(214+21. For a certain number of words, its value is

Yes (43947) 10, because the data of word type is an unsigned number (non-negative) represented by the original code, that is,10111.

+2 1 1+29+28+27+25+23+2 1+ 1) 10=(43947) 10;

5. desire

Each element has 4 bytes. After the implementation of fillchar(a, size(a), 1), it is (16843009) 10. This is because, for each element, after being filled with 1, it becomes:

The highest byte, the second highest byte

3 1 30 29 28 27 26 25 24 | 23 22 2 1 20 19 18 17 16

0 0 0 0 0 0 0 1 | 0 0 0 0 0 0 0 1

Next lowest byte

15 14 13 12 1 1 10 9

8 | 7 6 5 4 3 2 1 0

0 0 0 0 0 0 0 1 | 0 0 0 0 0 0 0 1

Longint data is a signed number represented by its complement, the highest bit is the sign bit, 0 means positive, 1 means negative. Since this number is positive, its complement, complement and original code are all.

0000000001000000010000001,and its value is (224+216+1)/kloc-

If fillchar(a, size(a), 255) is executed, what is the result?

From (255)10 = (111165438) 2, the complement is1/kloc. 11111is a negative number.

Its anti-code is111111165438. 0111111111/65440.

Step 6 be single

Each element has 4 bytes, all of which are 2.369472761724e-0038. This is because, for each element, the result filled with 1 is exactly the same as the binary code of type longint. however

The "interpretation" of this data by a single type is completely different:

A the most significant bit (bit 3 1) is the sign bit of an integer, where 0 is positive and 1 is negative.

B the next 8 bits (30th to 23rd bits) are rank codes represented by shift codes.

The last 23 bits (bits 22 to 0) of c represent mantissa.

The value of d single precision quantity is: 2 actual exponent * actual mantissa.

(1), if the order code = 0000000, the actual indicator =- 126, and the actual mantissa =(0. ) 2, of which? Binary code (0 or1) indicating the corresponding position; Obviously, in? When all zeros,

The value of this single precision quantity is 0.

② If the rank code is greater than 00000000 and less than11111,the actual index = rank code-(127) 6544.

(3) INF (infinity) If the sequence code =1111and the mantissa has reached the upper bound, it is considered infinite.

④ Floating-point operation error: If the sequence code =1111111,the mantissa is (00000000000000000000000000000).

100000000000000000000000).

⑤ NAN (non-digit: non-A)

Number) If the rank code =1111111,the mantissa is [1000000000000].

Next, let's analyze the value of a single precision number (single type) with binary code of 00000000010000001 ① most

The high bit is 0, indicating a positive number; ② The sequence code is 000000 10. If the binary number of 10 is 2, the actual index is 2-127 =-125, and ③ the mantissa is.

000000001000000010000001,actual mantissa =1.000000000010000000100000000/.

Change it to 10, and the cardinal number is1+2-7+2-15+2-23 =1.0078431367874145078/.

④ The value of this single precision number is+2-125 *1.00743136787414550786548+0258762.

7. Other real number types will not be listed one by one.

8. For collection type, if array type =' # '...z' of collection.

The result after executing fillchar(a, sizeof(a), 0): A is all empty sets; Sizeof(a) gives 120. Why is the value of sizeof(a) 120? origin

For the collection type, because the range of elements (such as' # '...z') must be given in advance, whether each element exists in a collection can be simply recorded by 0 or 1, and 0 indicates that the element does not belong to a certain collection.

Together, 1 indicates that the element belongs to a set, which means that only 1 binary bits can indicate whether 1 element belongs to a set, so we can mark all the norms by writing a string of binary codes according to the serial number of the element.

Whether the elements in the attachment belong to a collection. But there is a problem here: data is usually stored in bytes, not directly accessing every binary bit, so it must contain the range of elements given by the user.

Line adjustment, the adjustment principle is: the two ends are properly expanded, so that the serial number of the first element and the number of elements are exactly multiples of 8, so that the set can be stored in bytes. That is, if arrtype=set of

Char1... Char2 (char1,the constant of char2 should be defined in advance), then the range is extended to NewChar 1...NewChar2, where newchar 1=chr.

(ord(char 1)-ord(char 1)mod 8),new char 2 = chr(ord(char 2)+7-ord(char 2)mod

8)。 For arrtype = a group

#' ...'z', the range given by the user is # 35...# 122, so the actual extended range is # 32...# 127, and the number of elements is 96, so a table with 96 bits = 12 bytes is needed.

Therefore, each element in the array A (the element in the array) accounts for 12 bytes, and the *** 10 element accounts for 120 bytes.

Question: For arrtype=set of '# '..z'

What is the result after executing fillchar(a, sizeof(a), 135)? (135)10 = (100011) 2. Each element in array A, such as a[ 1], accounts for/kloc-.

10000 1 1 1 10000 1 1 1 10000 1 1 1 10000 1 1 1 10000 165438 +0 1 10000 1 1 1 10000 1 1 1 10000 1 1 1 10000 1 1 1 10000654 38+0 1 1 10000 1 1 1 10000 1 1 1,

***96 binary bits, the lowest bit is 1, indicating that the 1 set element (#32, i.e. space) in the extended range belongs to the set a[ 1], and the second bit is 1, indicating the second element (#33, i.e. "!" )) belongs to

Set a[ 1], the third bit is 1, indicating that the third element (#34 or "") belongs to set a[ 1], and the fourth bit is 0, indicating that the fourth element (#35 or "#") does not belong to set a[ 1].

Analogy. Other array elements a[2], a[3], ..., a[ 10] are the same as a[ 1].

[Example 3] Partial byte filling problem. All bytes are padded (because the sizeof () function is used).

For example, 1, if fillchar(a, 1, 55) is executed, that is, the first byte of variable A (the lowest byte of the element with the smallest subscript) is filled with (55) 10, and the principle is the same.

[Summary] Fillchar (var x; Count: words

The function of the value) process is to fill every byte of the low-count byte occupied by the specified variable X in the memory segment with a data value of one byte, because all data types have the same value of 2.

Binary codes have different interpretations, so the final result is very different. This paper discusses the internal storage mechanism of various types of data, which is helpful to deepen the understanding of data types.