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.1visual 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.1integer literal

integers are the simplest and most commonly used form of data. We write every day , and all 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:

q a decimal integer is a Ten as the basis of the digital system, every ten into one.

q by0,1,2,3,4,5,6,7,8,9consists of 10 basic numbers.

q a decimal integer cannot be 0 start.

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. Hex

" example 1-1 "in the computer, each color is made up of red, green, and blue colors. Each color typically uses the 0~255 8 8 bit binary numbers, Connected to form a number. This number is the value of this color. form the 1.1


Figure 1.1. Color Composition

For example, Brown by 102 the red, Wuyi of Green, 0 the blue composition. 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:

q   hexadecimal integers are 16

q   0~9 , a~f a~f Span style= "line-height:1.5" >10~15

q the representation of a hexadecimal number is 0x or 0X as a prefix.

for Brown It can be written as0x663300. Among them,0xis a hexadecimal prefix. and theis a102the hexadecimal notation; -is aWuyithe hexadecimal notation;xxis a0hexadecimal notation. With the decimal6697728compared to the hexadecimal0x663300It's much more intuitive. It is easy for programmers to set color values.

for hexadecimal and decimal conversions, here's an easy way to do it. Open windows calculator, in "View" menu, select the "Programmer" item in the drop-down list. Select Hex in the calculator that opens, and then enter a a corresponding decimal number 10 1.2


Figure 1.2 Programmer's Calculator

2. octal

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 1.4 1.3 2


Figure 1.3 Super Marie Game Interface Figure 1.4 Super Mario game levels

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 the scene . 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 An octal integer is a 8 as the basis of the digital system, every eight into one.

q by 0~7 composition.

q the octal number must be 0 as a prefix.

for scenes 56 can be written as 070 070 56 070

for the conversion of octal and decimal, here is a simple method. Open windows calculator, in "View" menu, select the "Programmer" item in the drop-down list. Select octal in the calculator that opens, and then enter 70 70 corresponding decimal number 56

Note: In order to differentiate between octal and decimal integers, octal integers are 0 as a prefix. 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.