Data representation literal integer literal

Source: Internet
Author: User

Data representation literal integer literal

To write a program, the first thing to face is data. How is the data represented in the program? Data is usually represented in two ways, depending on how it is represented: visual representation and reference representation. This chapter will explain in detail the two representations of this article selected from the plainly learn C # University PA .

1.1 Visual representation of data--literal

In code writing, data can often be written directly into the code. For these data, people can learn their meanings by literally expressing meanings, so they are also called literal quantities. Literals are also called constants. According to the data content represented by the literal, it is divided into digital literal and literal literal. This section will first explain the digital literal this article selected from plainly learn C # University PA .

Numeric data is divided into integers and decimals, depending on whether a fractional part is taken. Therefore, digital literals are also classified as integer literals and floating-point literals. Here's a look at the two types of literal numbers.

1.1.1 Integer literal

Integers are the simplest and most commonly used form of data. 100 and 32 of our daily writing are integers. In programming languages, this way of writing is called a decimal integer. In order to standardize the writing, the notation of decimal integers in programming, the following provisions:

The Q decimal integer is a 10-based digital system, every ten in one.

Q consists of 0, 1, 2, 3, 4, 5, 6, 7, 8, 90 basic figures.

Q decimal integers cannot start with 0.

Decimal expression is closest to people's usage habits, so the use is the most extensive. But in programming, there are some special areas, the use of decimal is not very convenient.

1.16 Binary

Example 1-1 in a computer, each color is paired with three colors: red, green, and blue. Each color typically uses 0~255 to represent the color depth, which is the 8-bit binary number. Then it will represent three colors, three sets of 8-bit binary digits, connected together to form a number. This number is the value of this color. The composition is shown in 1.1.

Figure 1.1: Color composition

For example, Brown is composed of 102 red, 51 green, and 0 blue. The decimal expression is 6697728. Such a number is difficult to see the composition of the color.

To make it easier for programmers to set color values, we can use hexadecimal notation. The hexadecimal writing code is as follows:

The Q hexadecimal integer is a 16-based digital system, every 16 in one, borrowing a 16.

Q is made up of 0~9,a~f. Among them, a~f corresponds to 10~15 respectively.

The representation of the Q hexadecimal number is prefixed with 0x or 0X.

For the brown can be written as 0x663300. Where 0x is the hexadecimal prefix. While 66 is the hexadecimal notation of 102, 33 is the hexadecimal notation for 51, and 00 is the hexadecimal notation for 0. The hexadecimal 0x663300 is much more intuitive than the decimal 6697728. It is easy for programmers to set color values.

For hexadecimal and decimal conversions, here's an easy way to do this. Open the Windows Calculator and select the programmer item from the drop-down list in the View menu. In the calculator that opens, select Hex, enter a, and then click Decimal to display the decimal Number 10 for hexadecimal number a. Convert the decimal with the hexadecimal programmer in Calculator 1.2 as shown.

Figure 1.2 Programmer's Calculator

2. Eight binary

In addition to hexadecimal and decimal, there is another common binary-eight binary. Let's look at a classic example.

"Example 1-2" in the Super Mario game, there are eight mark. And each mark is divided into four small clearance. Each small gateway is comprised of two scenes. Super Mario game interface with level settings 1.3 and 1.4 shown. In Figure 1.3, the game carries the first scene to the second small close of the first mark. This time the scene number corresponding to the entire game is 2. The progress of the whole game is recorded and identified by the scene number.

Figure 1.3 Super Mario game interface Figure 1.4 Super Mario game level

When the game developer let Mary into the eighth mark of the first small off the first scene. This is, if the decimal specification is used, the current game progress is scenario 56. For such a number, the developer must calculate by hand to come. In the event of an error, Mary should have "crossed". At this point, you can use the octal form to represent it. The eight-binary writing code is as follows:

Q octal Integer is a 8-based digital system, every eight in one.

Q is made up of 0~7.

Q The octal number must be prefixed with 0.

For scenario 56 It can be written as 070. That is, the octal number 070 and the decimal number 56 have the same meaning. Using octal number 070 can be very intuitive to see the current game progress of the eighth mark the first small off.

For octal and decimal conversions, here's an easy way to do this. Open the Windows Calculator and select the programmer item from the drop-down list in the View menu. Select octal in the Open calculator, enter 70, and then click Decimal to display the decimal number 56 for the octal number 70.

Note: In order to differentiate between octal and decimal integers, an octal integer is prefixed with 0. In order to differentiate between octal and hexadecimal, hexadecimal integers are prefixed with 0x or 0X this article has chosen to learn the C # University bully from plainly .

Data representation literal integer literal

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.