Typ całkowitoliczbowy (integer)

27 sierpnia 2013 | LoadingDodaj do biblioteki

Integer data type

In computer science, an integer is a datum of integral data type, a data type which represents some finite subset of the mathematical integers. Integral data types may be of different sizes and may or may not be allowed to contain negative values. Integers are commonly represented in a computer as a group of binary digits. The size of the grouping varies so the set of integer sizes available varies between different types of computers. Computer hardware nearly always provides a way to represent a processor register or memory address as an integer.

Value and representation

The name integer derives from the Latin integer (meaning literally "untouched," hence "whole."

The value of an item with an integral type is the mathematical integer that it corresponds to. Integral types may be unsigned (capable of representing only non-negative integers) or signed (capable of representing negative and non-negative integers).

An integer value is typically specified in the source code of a program as a sequence of digits optionally prefixed with + or −. Some programming languages allow other notations, such as hexadecimal (base 16) or octal (base 8).

The internal representation of this datum is the way the value is stored in the computer’s memory. Unlike mathematical integers, a typical datum in a computer has some minimal and maximum possible value.

Endianness - kurs angielskiego dla programistów - rysunek jajka
The most common representation of a positive integer is a string of bits, in the binary numeral system. The width or precision of an integral type is the number of bits in its representation. The order of the memory bytes storing the bits varies. It’s called endianness. In big endian systems bits are organized with the most significant bit on the left, and the least significant bit on the right. In contrast, in little endian systems the most significant bit is on the right and the least significant bit is on the left. Mixed forms are also possible although they are rare. Such systems are usually referred to as mixed-endian or middle-endian.

The term big-endian originally comes from Jonathan Swift’s satirical novel Gulliver’s Travels and was introduced by Danny Cohen in 1980.

In 1726, Jonathan Swift described in his satirical novel Gulliver’s Travels tensions in Lilliput and Blefuscu: whereas royal edict in Lilliput requires cracking open one’s soft-boiled egg at the small end, inhabitants of the rival kingdom of Blefuscu crack theirs at the big end (giving them the moniker Big-endians). The terms little-endian and endianness have a similar intent.

Danny Cohen’s "On Holy Wars and a Plea for Peace" published in 1980 ends with: "Swift’s point is that the difference between breaking the egg at the little-end and breaking it at the big-end is trivial. Therefore, he suggests, that everyone does it in his own preferred way. We agree that the difference between sending eggs with the little- or the big-end first is trivial, but we insist that everyone must do it in the same way, to avoid anarchy. Since the difference is trivial we may choose either way, but a decision must be made."

There are four well-known ways to represent signed numbers in a binary computing system. The most common is two’s complement, which allows a signed integral type with n bits to represent numbers from −2(n−1) through 2(n−1)−1.

Some computer languages define integer sizes in a machine-independent way; others have varying definitions depending on the underlying processor word size. Not all language implementations define variables of all integer sizes, and defined sizes may not even be distinct in a particular implementation. An integer in one programming language may be a different size in a different language or on a different processor.

Some languages, such as Lisp, Smalltalk, REXX and Haskell, support arbitrary precision integers (also known as infinite precision integers or bignums). Other languages which do not support this concept as a top-level construct may have libraries available to represent very large numbers using arrays of smaller variables, such as Java’s BigInteger class or Perl’s bigint package. These use as much of the computer’s memory as is necessary to store the numbers; however, a computer has only a finite amount of storage, so they too can only represent a finite subset of the mathematical integers. These schemes support very large numbers, for example one kilobyte of memory could be used to store numbers up to 2466 decimal digits long.

A four-bit quantity is known as a nibble (when eating, being smaller than a bite) or nybble (being a pun on the form of the word byte). One nibble corresponds to one digit in hexadecimal and holds one digit or a sign code in binary-coded decimal.

Bytes and octets

The term byte initially meant ‚the smallest addressable unit of memory’. In the past, 5-, 6-, 7-, 8-, and 9-bit bytes have all been used. 8-bit quantity is always referred to as octet. In modern usage byte almost invariably means eight bits, since all other sizes have fallen into disuse; thus byte has come to be synonymous with octet.

Words

The term word is used for a small group of bits which are handled simultaneously by processors of a particular architecture. The size of a word is thus CPU-specific. Many different word sizes have been used, including 6-, 8-, 12-, 16-, 18-, 24-, 32-, 36-, 39-, 48-, 60-, and 64-bit. Since it is architectural, the size of a word is usually set by the first CPU in a family, rather than the characteristics of a later compatible CPU. The meanings of terms derived from word, such as longword, doubleword, quadword, and halfword, also vary with the CPU and OS.

Practically all new desktop processors are capable of using 64-bit words, though embedded processors with 8- and 16-bit word size are still common. The 36-bit word length was common in the early days of computers.

One important cause of non-portability of software is the incorrect assumption that all computers have the same word size as the computer used by the programmer. For example, if a programmer using the C language incorrectly declares as int a variable that will be used to store values greater than 215−1, the program will fail on computers with 16-bit integers. That variable should have been declared as long, which has at least 32 bits on any computer.

Short integer

A short integer can represent a whole number which may take less storage, while having a smaller range, compared with a standard integer on the same machine.

Long integer

A long integer can represent a whole integer number whose range is greater than or equal to that of a standard integer on the same machine. A long integer commonly requires double the storage capacity of a standard integer, although this is not always the case.

Źródło: Wikipedia (tekst został dostosowany do potrzeb kursu)

Dictionary

9-bit byte
bajt 9-bitowy
a sequence of sth.
sekwencja/szereg czegoś
addressable
adresowalny
although this is not always the case
chociaż nie zawsze tak jest
arbitrary precision
dowolna precyzja
architecture
architektura
assumption
założenie
base 16
o podstawie 16
base 8
o podstawie 8
big endian
big endian
bignums
duże liczby
binary computing system
komputerowy system binarny
binary numeral system
binarny system liczbowy
byte
bajt
capable of sth.
zdolny do czegoś
class
klasa
computer hardware
sprzęt komputerowy
computer memory
pamięć komputera
CPU (Central Processing Unit)
procesor
CPU-specific
charakterystyczny dla procesora
datum
porcja danych
declare sth. as
zadeklarować coś jako
embedded processor
procesor wbudowany
endianness
„kolejność bitów”
fall into disuse
wyjść z użycia
finite subset
podzbiór skończony
greater than or equal to
większy niż lub równy
hexadecimal
szesnastkowy
in the early days of sth.
na początku istnienia czegoś, początkowo
infinite precision
nieskończona precyzja
integral data type
całkowitoliczbowy typ danych
integral type
typ całkowitoliczbowy
internal representation
wewnętrzna reprezentacja
invariably
niezmiennie
kilobyte of memory
kilobajt pamięci
language implementation
implementacja języka
least significant bit
najmniej znaczący bit
library
biblioteka
little endian
little endian
machine-independent
niezależny od sprzętu
mean
znaczyć, oznaczać
memory address
adres pamięci
mixed-endian
mixed-endian
most significant bit
najbardziej znaczący bit
negative
ujemny
negative value
wartość ujemna
nibble (nybble)
półbajt
non-negative integers
nieujemne liczby całkowite
non-portability
brak możliwości przenoszenia, nieprzenośność

notation
notacja
numbers from x through y
liczby od x do y
octal
ósemkowy
octet
oktet
of x size
rozmiaru x
of x type
typu x
OS (Operating System)
system operacyjny
package
pakiet
precision
precyzja, dokładność
prefixed with x
z przedrostkiem x
processor register
rejestr procesora
programmer
programista
quantity
ilość
range
zakres
rare
rzadki
referred to as…
nazywany…
represented in a computer as
reprezentowany w komputerze jako
set of integers
zbiór liczb całkowitych
set
zbiór
signed
ze znakiem
simultaneously
jednocześnie, równocześnie
software
oprogramowanie
source code
kod źródłowy
specify
określić
storage
pamięć (trwała)
string
łańcuch
subset of x
podzbiór x
the most common
najczęściej spotykany, najpospolitszy
the order of sth.
kolejność czegoś
the size of sth.
rozmiar czegoś
the term word is used for
terminem słowo określa się, termin słowo oznacza
to be capable of doing sth.
móc/potrafić coś zrobić
to correspond to sth.
odpowiadać czemuś
to handle
obsługiwać, wykorzystywać posługiwać się czymś
to provide a way to do sth.
umożliwiać zrobienie czegoś
to refer to sth. as…
nazywać coś…
to require
wymagać
to take less storage
zajmować mniej pamięci
top-level
najwyższego poziomu
two’s complement
dopełnienie dwójkowe
typically
zazwyczaj, typowo, normalnie
unlike sth./sb.
w odróżnieniu od kogoś/czegoś
unsigned
bez znaku
value of sth.
wartość czegoś
vary
zmieniać się, różnić się
whole number
liczba całkowita
width
szerokość
word
słowo

Exercises

  1. Answer the following questions
  2. Provide words for the definitions
  3. Provide Polish equivalents of these terms and expressions
  4. Provide English equivalents of these terms and expressions
  5. Fill in the gaps
  6. Fill in the gaps
  7. Translate the words in brackets into English
  8. Translate the following sentences into English
  9. Create sentences with the words provided
  10. Find out more about the following subjects

Grammar corner

Passive voice with modal verbs

Passive sentences can also be formed with modal verbs. The most commonly used modal verbs in passive sentences are can, should, would, may, might and must. The basic pattern we use for passive modals is the following:

 

subject + modal verb + be + passive participle

 

[1] Integral data types may be of different sizes and may or may not be allowed.

[2] Integral types may be unsigned or signed.

[3] …for example one kilobyte of memory could be used to store numbers up to 2466 decimal digits long.

 

In sentences [1] and [2] are used both positive and negative forms of the verb may in the passive , may be allowed or may not be allowed.

Sentence [3] is an example of the verb could in the passive form.

 

Exercise: Change the following sentences into the passive. Start your sentences with the words provided.

Licencja: CC-BY-SA 3.0

Odpowiedz

Twój adres email nie zostanie opublikowany. Pola, których wypełnienie jest wymagane, są oznaczone symbolem *