Current location - Training Enrollment Network - Books and materials - Introduction and details of binary system
Introduction and details of binary system
Basic concepts? Binary is a digital system widely used in computing technology. Binary data are numbers represented by 0 and 1. Its cardinal number is 2, the carry rule is "every two enters one", and the borrowing rule is "borrowing one as two", which was discovered by the German master of mathematical philosophy Leibniz in18th century. The current computer system basically uses a binary system.

Data is mainly stored in the form of complement in the computer. The binary in the computer is a very tiny switch, where "On" stands for 1 and "Off" stands for 0.

One of the important signs called the third scientific and technological revolution in the 20th century is the invention and application of computers, because digital computers can only recognize and process codes consisting of' 0'. 1' symbol string. Its operating mode is binary. /kloc-in the 9th century, George Bull, an Irish logician, transformed the thinking process of logical propositions into some kind of algebraic calculus with the symbol "0". "1", binary is binary. 0, 1 is the basic operator. Because it only uses 0 and 1, it is very simple and convenient, and easy to realize electronically.

This paper briefly introduces the invention and application of computer, which is called one of the important signs of the third scientific and technological revolution in the 20th century, because digital computers can only recognize and process codes consisting of' 0'. 1' symbol string. Its operating mode is binary. /kloc-in the 9th century, George Bull, an Irish logician, transformed the thinking process of logical propositions into some kind of algebraic calculus with the symbol "0". "1", binary is binary. 0, 1 is the basic operator. Because it only uses 0 and 1, it is very simple and convenient, and easy to realize electronically.

Binary, like hexadecimal and octal, is carried by the power of two.

Main features and advantages: binary digital devices are simple and reliable, and few components are used;

There are only two numbers, 0 and 1, so each number can be represented by any element in two different stable states.

The basic operating rules are simple and easy to operate.

Disadvantages When a number is expressed in binary, there are many digits. Therefore, in practical use, the decimal system is used first, then sent to the digital system, and then converted into binary numbers after being sent to the machine, so that the digital system can operate, and then the binary is converted into decimal for people to read after the operation.

The conversion between binary and hexadecimal is more important. However, there is no need to calculate the conversion between the two. Every C and C++ programmer can see binary numbers and convert them directly into hexadecimal numbers, and vice versa.

We are the same, as long as we finish this section, we can do it.

First, let's look at a binary number:111. What is this?

You may want to calculate it like this:1* 20+1* 21* 2+1* 2 3 =1*1.

However, since 111has only four digits, we must directly remember the weight of each digit and record it from high to low: 8, 4, 2,1. That is, the weight of the highest bit is 2 3 = 8, followed by 2 2 = 4, 21= 2, 2 0 =1.

Remember 842 1, for any 4-bit binary number, we can quickly calculate its corresponding 10 binary value.

All possible values of the four-digit binary number xxxx are listed below (the middle part is skipped).

A fast calculation method of binary numbers with only 4 decimal values and 16 binary values

1 1 1 1 = 8+4+2+ 1 = 15 F

1 1 10 = 8+4+2+0 = 14 E

1 10 1 = 8+4+0+ 1 = 13d

1 100 = 8+4+0+0 = 12c

10 1 1 = 8+0+2+ 1 = 1 1 B

10 10 = 8+0+2+0 = 10 A

100 1 = 8 + 0 + 0 + 1 = 9 9

....

000 1 = 0 + 0 + 0 + 1 = 1

0000 = 0 + 0 + 0 + 0 = 0 0

Binary numbers are converted into hexadecimal, that is, they are converted into hexadecimal in units of 4 bits.

Such as (the upper line is a binary number, and the lower line is a corresponding hexadecimal number):

1 1 1 1 1 10 1 , 10 10 0 10 1 , 100 1 10 1 1

Federal development agency, A 5, 9 B

Conversely, when we see FD, how can we quickly convert it into a binary number?

First convert f:

When we see F, we need to know that it is 15 (maybe you are not familiar with the six numbers A ~ F), and then how can 15 be rounded with 842 1? It should be 8+4+2+ 1, so all four digits are1:11.

Then convert d:

When you see D, you know it's 13, 13. How to add 842 1? It should be: 8+4+0+ 1, that is: 1 10 1.

So FD is converted into a binary number, which is:11111.

Because it is quite straightforward to convert hexadecimal into binary, when we need to convert a decimal number into binary, we can also convert it into 16 first, and then convert it into binary.

For example, decimal number 1234 is converted into binary number, and if you want to divide by 2 all the time to get binary number directly, you need to calculate it many times. So we can divide by 16 to get 16:

Dividend calculation process quotient remainder

1234 1234/ 16 77 2

77 77/ 16 4 13 (D)

4 4/ 16 0 4

The hexadecimal number of the result 16 is 0x4D2.

Then we can write the binary form of 0x4D2 directly: 010011kloc-0/0010.

Among them, the mapping relationship is:

0 100 - 4

1 10 1 - D

00 10 - 2

Similarly, if a binary number is long, we need to convert it into 10. We can also convert this binary number into 16 and then convert it into 10.

The following is an example of a binary number of type int:

0 1 10 1 10 1 1 1 100 10 1 10 10 1 1 1 1 000 1 10 1 1

Let's convert it into four-bit16: 6d5af1b.

Basic operations The basic laws of arithmetic operations on binary data are very similar to those of decimal numbers. The most commonly used are addition and multiplication.

There are four cases of binary addition: 0+0=0.

0+ 1= 1

1+0= 1

1+ 1= 10

Ps:0 carries 1.

Example 1 103 Find the sum of (11) 2+(101) 2.

Solution:

1 1 0 1

+ 1 0 1 1

-

1 1 0 0 0

There are four cases of binary multiplication: 0×0=0.

1×0=0

0× 1=0

1× 1= 1

Example 1 104 find the product of (1 1 10)2 times (10 1)2.

Solution:

1 1 1 0

× 1 0 1

-

1 1 1 0

0 0 0 0

1 1 1 0

- ?

1 0 0 0 1 1 0

(These calculations are the same as decimal addition or multiplication, but the decimal places are different. Decimal digits don't go to ten places, so here are two places. )

3. Binary subtraction

0-0=0, 1-0= 1, 1- 1=0, 10- 1= 1。

4. Binary division

0÷ 1=0, 1÷ 1= 1。 [ 1-2]

5. Binary modular addition

A special algorithm for binary addition, subtraction, multiplication and division.

Modular addition is similar to addition, but it doesn't need carry. This algorithm is widely used in game theory.

Decimal to binary conversion in computer

The decimal fraction in a computer is obtained in binary, usually multiplied by two.

For example, 0.65 is converted to binary:

0.65 * 2 = 1.3 take 1, leave 0.3 and continue to multiply by two to round off.

0.3 * 2 = 0.6 takes 0, and the remaining 0.6 continues to be multiplied by two for rounding.

0.6 * 2 = 1.2 take 1, leave 0.2 and continue to multiply by two to round.

0.2 * 2 = 0.4 takes 0, and the remaining 0.4 continues to be multiplied by 2 for rounding.

0.4 * 2 = 0.8 takes 0, and the remaining 0.8 continues to be multiplied by two for rounding.

0.8 * 2 = 1.6 take 1, leave 0.6 and continue to multiply by two to round.

0.6 * 2 = 1.2 take 1, leave 0.2 and continue to multiply by two to round.

.......

Loop until the accuracy limit is reached (therefore, the decimal saved by the computer is usually wrong, so in programming, if you want to compare whether two decimals are equal, you can only compare whether they are equal within a certain accuracy range. )。 At this time, the decimal 0.65 can be expressed in binary as:1010011.

In addition, it is worth mentioning that in today's computers, except decimal is signed, others such as binary, octal and 16 are unsigned.

How to Convert Decimal Numbers into Binary Numbers, Octal Numbers and Hexadecimal Numbers;

Methods of converting binary numbers, octal numbers and hexadecimal numbers into decimal numbers: weighted expansion and summation

Conversion between binary and decimal (1) Binary to decimal

Method: "Sum by weight expansion"

Example: (1011.01) 2 = (1× 2 3+0× 2 2+/kloc-0 /× 21.

=(8+0+2+ 1+0+0.25) 10

=( 1 1.25) 10

Law: the number of digits in the unit is 0, the number of decimals is 1, ..., which increases in turn, while the number of digits in the tenth is-1, and the number of digits in the percentile is -2, ..., which decreases in turn.

Note: Not any decimal fraction can be converted into a binary number with a limited number of digits.

(2) Decimal to binary

Decimal integer to binary number: "Divide by 2 for remainder, in reverse order" (Divide by 2 for remainder method).

For example: (89)10 = (1011001) 2

89÷2 …… 1

44÷2 ……0

22÷2 ……0

1 1÷2 …… 1

5÷2 …… 1

2÷2 ……0

1

Decimal decimal number to binary number: "round by 2, in order" (round by 2)

For example: (0.625)10 = (0.101) 2

0.625X2= 1.25 …… 1

0.25 X2=0.50 ……0

0.50 X2= 1.00 …… 1

Binary representation of decimal 1 to 100.

0=0

1= 1

2= 10

3= 1 1

4= 100

5= 10 1

6= 1 10

7= 1 1 1

8= 1000

9= 100 1

10= 10 10

1 1= 10 1 1

12= 1 100

13= 1 10 1

14= 1 1 10

15= 1 1 1 1

16= 10000

17= 1000 1

18= 100 10

19= 100 1 1

20= 10 100

2 1= 10 10 1

22= 10 1 10

23= 10 1 1 1

24= 1 1000

25= 1 100 1

26= 1 10 10

27= 1 10 1 1

28= 1 1 100

29= 1 1 10 1

30= 1 1 1 10

3 1= 1 1 1 1 1

32= 100000

33= 10000 1

34= 1000 10

35= 1000 1 1

36= 100 100

37= 100 10 1

38= 100 1 10

39= 100 1 1 1

40= 10 1000

4 1= 10 100 1

42= 10 10 10

43= 10 10 1 1

44= 10 1 100

45= 10 1 10 1

46= 10 1 1 10

47= 10 1 1 1 1

48= 1 10000

49= 1 1000 1

50= 1 100 10

5 1= 1 100 1 1

52= 1 10 100

53= 1 10 10 1

54= 1 10 1 10

55= 1 10 1 1 1

56= 1 1 1000

57= 1 1 100 1

58= 1 1 10 10

59= 1 1 10 1 1

60= 1 1 1 100

6 1= 1 1 1 10 1

62= 1 1 1 1 10

63= 1 1 1 1 1 1

64= 1000000

65= 100000 1

66= 10000 10

67= 10000 1 1

68= 1000 100

69= 1000 10 1

70= 1000 1 10

7 1= 1000 1 1 1

72= 100 1000

73= 100 100 1

74= 100 10 10

75= 100 10 1 1

76= 100 1 100

77= 100 1 10 1

78= 100 1 1 10

79= 100 1 1 1 1

80= 10 10000

8 1= 10 1000 1

82= 10 100 10

83= 10 100 1 1

84= 10 10 100

85= 10 10 10 1

86= 10 10 1 10

87= 10 10 1 1 1

88= 10 1 1000

89= 10 1 100 1

90= 10 1 10 10

9 1= 10 1 10 1 1

92= 10 1 1 100

93= 10 1 1 10 1

94= 10 1 1 1 10

95= 10 1 1 1 1 1

96= 1 100000

97= 1 10000 1

98= 1 1000 10

99= 1 1000 1 1

100= 1 100 100

Conversion from octal to binary Binary number is converted into octal number: starting from decimal point, the integer part is left and the decimal part is right, and every 3 digits are represented by an octal number. If it is less than 3 digits, make up 3 digits with "0" to get an octal number.

Convert octal number into binary number: convert each octal number into a 3-bit binary number to get a binary number.

The correspondence between octal numbers and binary numbers is as follows:

000->; 0 100->; four

00 1->; 1 10 1->; five

0 10->; 2 1 10->; six

0 1 1->; 3 1 1 1->; seven

Example: Convert octal 37.4 16 to binary number:

3 7 .4 1 6

0 1 1 1 1 1 . 100 00 1 1 10

Namely: (37.416) 8 = (111.10001) 2.

Example: Convert binary10110.001to octal:

0 1 0 1 1 0 .0 0 1 1 0 0

2 6 . 1 4

Namely: (10110.01) 2 = (26.14) 8.

Hexadecimal and binary conversion binary numbers are converted into hexadecimal numbers: starting from the decimal point, the integer part is left and the decimal part is right, and every four digits are represented by a hexadecimal number. If it is less than four digits, you should form four digits with "0" to get a hexadecimal number.

Convert Hexadecimal Numbers into Binary Numbers: Convert each hexadecimal number into a 4-bit binary number and you get a binary number.

The corresponding relationship between hexadecimal number and binary number is as follows:

0000->; 0 0 100->; 4 1000->; 8 1 100->; C

000 1->; 1 0 10 1->; 5 100 1->; 9 1 10 1->; D

00 10->; 2 0 1 10->; 6 10 10->; a 1 1 10->; E

00 1 1->; 3 0 1 1 1->; 7 10 1 1->; b 1 1 1 1->; F

Example: Convert hexadecimal number 5DF.9 to binary number:

The fifth day, the ninth day

0 10 1 1 10 1 1 1 1 1 . 100 1

Namely: (5df.9)16 = (1011111/.

Example: Convert the binary number110001.11into hexadecimal:

0 1 10 000 1 . 1 1 10

6 1 .E

Namely: (110001.11) 2 = (61. E) 16。

Other information is regarded as the invention and application of the computer, which is one of the important symbols of the third scientific and technological revolution in the 20th century. It has a binary operation mode, which proves that the Leibniz principle is correct.

Representation of binary data Binary data also adopts position counting method, and its bit weight is a power based on 2. For example, for binary data110.11,the order of weights is 2 2, 21,2- 1, 2-2. For integers with n digits and decimals with m digits, binary data is expressed by the expansion of weighted coefficients, which can be written as:

(a(n- 1)a(n-2)…a(-m))2=a(n- 1)×2^(n- 1)+a(n-2)×2^(n-2)+……+a( 1)×2^ 1+a(0)×2^(0)+a(- 1)×2^(- 1)+a(-2)×2^(-2)+……+a(-m)×2^(-m)

General binary data can be written as: (a (n-1) a (n-2) ... a (1) a (0). a (- 1) a (-2) … a (-m)) 2。

note:

1. In the formula, aj represents the coefficient of the j-th position, which is one of 0 and 1.

2. The (n- 1) in a (n-1) is a subscript, and the input method cannot be entered, so it is enclosed in brackets to avoid confusion.

3.2 2 represents the square of 2, and so on.

Example 1 102 binary data11is written as a weighting coefficient.

Solution: (11) 2 = (1× 2 2)+(1× 21)+(1× 2 0)

Binary, like hexadecimal and octal, is carried by the power of two.

Leibniz and Binary kept a precious manuscript in the famous Schlos *** iliothke zu Gotha in Thuringia, Germany, entitled "1 and 0, the magical origin of all numbers. This is an excellent example of creating secrets, because everything comes from God. " This is the handwriting of Gottfried Wilhelm Leibniz (1646- 17 16). However, Leibniz has only a few pages of extremely refined description of this magical and wonderful digital system.

Leibniz not only invented binary system, but also endowed it with religious connotation. In a letter to Joachim Bouvier, a French Jesuit priest who was preaching in China at that time (1662- 1732), he said: "The first day began with 1, that is, God. The beginning of the second day is 2 ... On the seventh day, everything is available. Therefore, this last day is also the most perfect. Because at this time, everything in the world has been created. So it is written as' 7', that is,' 1 1' (binary11equals decimal 7), without 0. Only when we only use 0 and 1 to represent this number can we understand why the seventh day is the most perfect and why 7 is a sacred number. It is particularly noteworthy that its characteristics (writing binary 1 1 1) are related to the trinity. "

Bouvier is a master of sinology, and his introduction to China is one of the most important reasons for the China fever in European academic circles in the 17 and18th centuries. Bouvier is a good friend of Leibniz and keeps frequent correspondence with him. Leibniz once translated many articles of Bouvier into German and published them. It was Buwei who introduced Zhouyi and the gossip system to Leibniz, and explained the authoritative position of Zhouyi in China culture.

Eight diagrams is a divination system composed of eight symbol groups, which are divided into continuous and discontinuous horizontal lines. In Leibniz's view, these two symbols, which were later called "Yin" and "Yang", were China replicas of his binary system. He felt that the relationship between this symbol system from China ancient culture and his binary system was too obvious, so he asserted that the binary system was the most perfect universal logic language in the world.

Another person who may arouse Leibniz's interest in gossip is Wilhelm Ernst Tentzel, who was then the head of the Dagong Coin collection room in Thuringia and one of Leibniz's good friends. There is a coin with a gossip symbol in the coin collection he is in charge of.

Contact China Yijing

1679 On March 5th, Gottfried Wilhelm Leibniz invented a calculation method, which changed the original ten digits into two digits, namely 1 and 0. 170 1 year, he wrote to Maldi (Chinese name Min Mingming) and Buwei (Chinese name Bai Jin), priests in Beijing, informing them of their new inventions, hoping to arouse the interest of Emperor Kangxi, an arithmetic enthusiast in his mind.

Bai Jin was surprised because he found that this kind of "binary arithmetic" was very similar to a symbol system based on two symbols in ancient China, which consisted of a straight line and two short lines, namely ── and ──. This is the basic part of China's most famous and possibly oldest book, The Book of Changes. According to current speculation, this book was produced at the beginning of the first Millennium BC. At first, it was mainly used for divination, and the two symbols in it may represent "yes" and "no" respectively.

Leibniz was surprised by this similarity. Like his pen pal Bai Jin, he is also convinced of the significance of the Book of Changes in mathematics. He thinks that China people in ancient times mastered the binary system, which far surpassed China people in science. Now we can say for sure that this explanation has nothing to do with the Book of Changes. The Book of Changes is not a math book, but a "prophecy book", which has gradually evolved into a "wisdom book" in the long history. The short line in the book refers to the opposition between yin and yang, that is, heaven and earth, light and darkness, creator and nature. Six hexagrams appear in different combinations, and people can make different explanations for the changes of nature and human life. Confucius. Sinarum philosopher ("Confucius, China thinker, ..."), Belgian priest P. Guli (Chinese name Bai Yingli), published the Book of Changes with 64 hexagrams for the first time in Europe.

This attempt to link mathematics with the Book of Changes in ancient China is impractical. Leibniz's binary mathematics points not to ancient China, but to the future. Leibniz recorded his binary system in his diary in March 1679, and at the same time, he designed a machine that can complete digital calculation. Today's modern technology has turned this idea into reality, which was unimaginable in the Leibniz era.

The reason why computers use binary.

The implementation of (1) technology is simple, and the computer consists of logic circuits, which usually have only two states, namely, the on-off state of the switch, which can be represented by "1" and "0".

(2) Simplifying operation rules: There are three combinations of sum and product operations of two binary numbers, and the operation rules are simple, which is beneficial to simplifying the internal structure of the computer and improving the operation speed.

(3) Suitable for logical operation: logical algebra is the theoretical basis of logical operation, and the binary has only two digits, which coincides with the "truth" and "false" in logical algebra.

(4) Easy conversion, and easy conversion between binary numbers and decimal numbers.

(5) Using binary to represent data has strong anti-interference ability and high reliability. Because each data has only two states of high and low, it can still be reliably distinguished whether it is high or low when it is disturbed to a certain extent.

Before the reform and opening up, most people in China didn't know what a computer was. 1980, the first American personal computer (PC) equipped with 8086CPU chip went on the market. In the early 1980s, imported computers appeared in China. An Apple computer costs nearly 20,000 yuan, which is hundreds of times the salary of ordinary cadres and workers, and individuals simply can't afford it. After the 1990s, with the popularity of the Internet in China, computers gradually became familiar to people in China.

Faced with foreign advanced science and technology, some traditional Chinese people are unconvinced. They don't even have basic mathematical knowledge, but they say that the principle of computer binary originated from China's Zhouyi. These intellectuals have the same characteristics. While vigorously promoting the use of traditional culture to resist western culture, they like to pull a foreign celebrity to encourage themselves. However, it is overlooked that since the ancestors' things are so great, why can't China people invent them and let the westerners Leibniz take the lead?

Both airplanes and birds can fly in the sky, but the principle of airplanes does not come from birds. Similarly, Leibniz has seen China's Taiji diagram, and he can't prove that the computer binary principle originated from the Book of Changes.

It is said that Fuxi created gossip. The legendary Fuxi era has a history of more than 5000 years. Humans had the ability to count as early as 5,000 years ago, but it was not until 628 AD that Indian Brahmagupta first used O. Bhaskara (an Indian in the 2nd century/kloc-0) to point out that a positive number has two square roots, one is positive and the other is negative. (British M. Klein, Mathematics: The Loss of Determinism, Hunan Science and Technology Press).

0 not only means "none" or "none", such as a temperature of 0 degrees, but also means no temperature. Using 0 can establish a frame of reference, for example, take any point on a straight line as 0, and the left side of 0 point is negative and the right side is positive.

Anyone who has studied computer principles knows that the high and low levels of computer circuits correspond to binary numbers 1 and 0. If the high level is 1 and the low level is 0; Conversely, the high level is 0 and the low level is 1. This is a question of positive logic and anti-logic. The working principle of the computer is based on Boolean algebra, which carries out logical operations. Although the computer circuit is very complicated, the basic unit is very simple, which consists of OR gate, AND gate, NOT gate, NAND gate, NOR gate, XOR gate, XOR gate and so on.

Because computers are high-tech, some people take it for granted that binary systems are also high-tech. For example, Professor Mao Peige of Lecture Room said in his book Graphic Zhouyi that binary system is "the most advanced mathematical system in the world". "The 20th century is called the invention and application of computers, which is one of the important symbols of the third scientific and technological revolution, and its operation mode is binary. It not only proves that Leibniz's principle is correct, but also proves that the mathematical principle of the Book of Changes is great. "

Professor Mao represents the views of a considerable number of people with traditional culture in China. This is ignorance of the mathematical system. There is no "right" or "wrong" in the principle of the mathematical system, let alone "advanced" or "backward".

What format is used for mathematical operations depends on what occasion and what convenience is used. There are binary, octal, decimal, hexadecimal, sexagesimal, … and so on in mathematics. In principle, any number system can be used as long as it is practical. A year 12 months is a decimal, and 365 days a year is a decimal. Numbers in different decimals can be converted to each other, such as decimal 135, binary100011,and binary1kloc-0/into decimal 5. Obviously, it is very simple to divide decimal number 135 by 5 manually, but dividing decimal number100011by binary number1kloc-0/is the most clumsy calculation.

The eight diagrams in the Book of Changes are all marked with a long line "one" and a broken line "-"(archaeological evidence of Mawangdui in the Western Han Dynasty shows that the negative line is "

Some people think that it is binary to regard the positive "one" of gossip as 1 and the negative "-"as 0. This is far-fetched, because in the age of gossip, there is no concept of 0 and 1.

The two hexagrams of Gankun symbolize heaven and earth. The dry divination consists of three positive ones superimposed on the top, and three negative ones superimposed on the top and bottom. If the symbol "one" is regarded as 1 and the symbol "-"is regarded as 0, then these three hexagrams are binary11,corresponding to decimal 7; The three hexagrams of Kun gua are binary 000, corresponding to decimal 0.

"Cohesion" said: "It is easy to have Tai Chi, which means to have two instruments, two instruments give birth to four images, and four images give birth to gossip." Tai Chi means making something out of nothing, making something out of nothing, and producing gossip. If 0 equals zero, Tai Chi is 0. Isn't this inconsistent with the above saying that Kun is 0? Moreover, the "numbers" of the eight hexagrams of Cognac, Dui, Li San, Paul, Xunwu, Liu Kan, Genqi and Kumba cannot correspond to the "binary numbers" converted by their six hexagrams.

Two eight diagrams are superimposed into sixty-four hexagrams, each consisting of six hexagrams. For example, hexagrams are six ones, corresponding to binary11111,and converted into decimal, 25+24+23+22+21 There are six negative signs "-"in Kun Gua, corresponding to binary 000000. Convert to decimal, or 0. The "number" of sixty-four hexagrams cannot correspond to the "binary number" converted from its six hexagrams.

Ancient Chinese characters have "zero", which is not equal to 0. The meaning of zero is: 1, local finely divided, as opposed to the whole, such as fragmentary, ten yuan and eight cents; 2, falling, such as carving zero. The modern meaning of zero can be nothing, such as "everything starts from zero"

Without the number 0, there is no way to talk about binary system (it doesn't matter whether there is 0 or not, 0 and 1 just represent the on-off of words. )。

The Book of Changes has mathematical principles, and 8864 hexagrams have simple arithmetic operations, but the binary system originated from gossip, which is based on misinformation. The eight diagrams divination symbols drawn by ancestors in ancient times have become the mathematical principles of high-tech computers, which is undoubtedly a modern version of the Arabian Nights.

Processing binary data in the database

When we use databases, we sometimes use images or other binary data. At this time, you must use getchunk method to get binary large objects from the table, and we can also use AppendChunk to insert data into the table.

This is how we usually get data!

Getdata=rs ("field name")

This is the price of getting binary.

Size=rs ("field name"). actual size

getdata=rs("fieldname ")。 Getchunk (size)

As can be seen from the above, we must first get the size of the binary data, and then repair it. This seems to be a common way to deal with binary data in ASP, and we also use this method when we get all the data from the client.

Let's see how to add binary data to the database.

Rs ("field name"). Appendchunk binary data

One step!

In addition, get the data out step by step with getchunk and appendchunk!

Let's demonstrate an example of obtaining data!

Addsize=2

totalsize=rs("fieldname ")。 actual size

offsize=0

do Where offsize binary data = RS(" field name ")。 getchunk(offsize)

Data = data & binary data

offsize=offsize+addsize

ring

When this program is completed, the data is the data we take out.