Chapterبەش 6 · Lectureوانە 6.1

Notation in Computing: mod, Bases, Big-O and Code Operatorsهێماکان لە کۆمپیوتەردا: mod، بنچینەکان، نیشانەی O-ی گەورە و کارپێکەرەکانی کۆد

How to read the notation of computing: a mod na \bmod n and a≡b(modn)a \equiv b \pmod{n} vs % and // with negative numbers; base subscripts (1010)2(1010)_2 and the prefixes 0b, 0o, 0x (and Java's leading-zero octal); powers of two, b, B and Ki; O(n)O(n), O(log⁡n)O(\log n), Θ and Ω; log⁡2n\log_2 n steps; maths vs Python, Java, MATLAB and Excel operators; indexes from 1 or from 0; σ, π and ⋈ in databases.

چۆن بخوێنیتەوە: a mod na \bmod n و a≡b(modn)a \equiv b \pmod{n} بەرامبەر % و // لەگەڵ ؛ ، (1010)2(1010)_2 و 0b، 0o، 0x (و سفری پێشەوەی Java)؛ 2، b، B و Ki؛ O(n)O(n)، O(log⁡n)O(\log n)، Θ و Ω؛ هەنگاوەکانی log⁡2n\log_2 n؛ بیرکاری بەرامبەر Python، Java، MATLAB و Excel؛ لە 1ـەوە یان لە 0ـەوە؛ σ، π و ⋈ لە .

16 min read17 خولەک خوێندنەوە · 16 stepsهەنگاو

What you will learnچی فێر دەبیت

  • Read a mod na \bmod n, a≡b(modn)a \equiv b \pmod{n}, div and ⌊a/n⌋\lfloor a/n \rfloor, and predict % and // with negative numbers in Python and Java.
  • Read base subscripts and code prefixes, check that the digits fit the base, and avoid Java's leading-zero octal.
  • Read O(n2)O(n^2), Θ and Ω, know that big-O's = goes one way, and count binary-search steps with log⁡2n\log_2 n.
  • Translate maths signs into Python, Java, MATLAB and Excel operators (** vs ^, ==, != ~= <>, ←) and say them in Kurdish.
  • Move between x1x_1, v(1) and v[0], and read σ, π and ⋈ in a database book.
  • a mod na \bmod n، a≡b(modn)a \equiv b \pmod{n}، div و ⌊a/n⌋\lfloor a/n \rfloor بخوێنیتەوە و ئەنجامی % و // لەگەڵ لە Python و Javaـدا پێشبینی بکەیت.
  • و کۆد بخوێنیتەوە، بپشکنیت لەگەڵ دەگونجێن و خۆت لە سفری پێشەوەی Java بپارێزیت.
  • O(n2)O(n^2)، Θ و Ω بخوێنیتەوە، بزانیت =ـی تەنیا یەک ئاڕاستەیە و هەنگاوەکانی بە log⁡2n\log_2 n بژمێریت.
  • بیرکاری بکەیت بە Python، Java، MATLAB و Excel (** بەرامبەر ^، ==، != ~= <>، ←) و بە کوردی بیانخوێنیتەوە.
  • لە نێوان x1x_1، v(1) و v[0]ـدا بگوازیتەوە و σ، π و ⋈ لە کتێبێکی بخوێنیتەوە.

a mod na \bmod n and a≡b(modn)a \equiv b \pmod{n}a mod na \bmod n و a≡b(modn)a \equiv b \pmod{n}

mod has two jobs. As an operation, a mod na \bmod n is the remainder when a is divided by n: 17 mod 5=217 \bmod 5 = 2, because 17=3×5+217 = 3 \times 5 + 2. Read it “seventeen mod five”. As a relation, a≡b(modn)a \equiv b \pmod{n} says that a and b leave the same remainder: 17≡2(mod5)17 \equiv 2 \pmod{5}, “17 is congruent to 2 modulo 5” (≡ and :=). The quotient has names too: adiv⁡na \operatorname{div} n or ⌊a/n⌋\lfloor a/n \rfloor. Always a=(adiv⁡n)⋅n+(a mod n)a = (a \operatorname{div} n) \cdot n + (a \bmod n). A clock works mod 12, as the animation shows.

mod دوو کاری هەیە. وەک ، a mod na \bmod n بریتییە لەو کە لە a بەسەر nـدا دەمێنێتەوە: 17 mod 5=217 \bmod 5 = 2، چونکە 17=3×5+217 = 3 \times 5 + 2. بیخوێنەوە «⁦17⁩ مۆد 5» یان « ⁦17⁩ بەسەر 5». وەک پەیوەندی، a≡b(modn)a \equiv b \pmod{n} دەڵێت a و b هەمان هەیە: 17≡2(mod5)17 \equiv 2 \pmod{5}، بە ئینگلیزی 17 is congruent to 2 modulo 5 (≡\equiv و :=:=). ئەنجامی ناوی هەیە: adiv⁡na \operatorname{div} n یان ⌊a/n⌋\lfloor a/n \rfloor. هەمیشە a=(adiv⁡n)⋅n+(a mod n)a = (a \operatorname{div} n) \cdot n + (a \bmod n). کاتژمێر بە ⁦mod 12⁩ کار دەکات، وەک ئەنیمەیشنەکە پیشانی دەدات.

Animation of a 12-hour clock. The hand starts at 12: where is it after 15 hours? After 12 hours it has made one full turn and is back at 12, 12 = 1 × 12 + 0. Three more hours take it to 3: 15 = 1 × 12 + 3, so 15 mod 12 = 3, the remainder. 15 and 3 point to the same place: 15 ≡ 3 (mod 12), “15 is congruent to 3 modulo 12”, and also 27 ≡ 15 ≡ 3 (mod 12). Last frame: one hour before 12 is 11, so −1 mod 12 = 11; in Python -1 % 12 gives 11, in Java -1 % 12 gives -1.
Animation of a 12-hour clock. The hand starts at 12: where is it after 15 hours? After 12 hours it has made one full turn and is back at 12, 12 = 1 × 12 + 0. Three more hours take it to 3: 15 = 1 × 12 + 3, so 15 mod 12 = 3, the remainder. 15 and 3 point to the same place: 15 ≡ 3 (mod 12), “15 is congruent to 3 modulo 12”, and also 27 ≡ 15 ≡ 3 (mod 12). Last frame: one hour before 12 is 11, so −1 mod 12 = 11; in Python -1 % 12 gives 11, in Java -1 % 12 gives -1.
Clock arithmetic: 15 mod 12=315 \bmod 12 = 3 and 15≡3(mod12)15 \equiv 3 \pmod{12}.ژماردنی کاتژمێر: 15 mod 12=315 \bmod 12 = 3 و 15≡3(mod12)15 \equiv 3 \pmod{12}.CêIT

Mod is everywhere in computing. The Caesar cipher shifts letters with Ek(m)=(m+k) mod 26E_k(m) = (m + k) \bmod 26, so Z wraps round to A (The oldest example: the Caesar cipher), and a mod-n counter starts again at 0 after n − 1 (Counters that stop early: mod-n).

mod لە هەموو شوێنێکی هەیە. پیتەکان بە Ek(m)=(m+k) mod 26E_k(m) = (m + k) \bmod 26 دەجووڵێنێت، بۆیە Z دەگەڕێتەوە سەر A (کۆنترین نموونە: شفرەی قەیسەر) و ⁦mod-n⁩ دوای ⁦n − 1⁩ دیسان لە 0ـەوە دەست پێدەکاتەوە (ژمێرەرە دیجیتاڵەکانی ⁦mod-n⁩).

% and // in code: watch the negative numbers% و // لە کۆددا: ئاگاداری ژمارە سالبەکان بە

Most languages write mod as %. For positive numbers they all agree: 17 % 5 is 2. For a negative number they do not. Python's % takes the sign of the number you divide by, like  mod \bmod in maths, Excel's MOD and MATLAB's mod: -7 % 3 is 2. And Python's // is floor division, ⌊a/n⌋\lfloor a/n \rfloor: -7 // 3 is −3, because −2.33… rounded down is −3.

زۆربەی زمانەکان mod بە % دەنووسن. بۆ هەموویان کۆکن: 17 % 5 دەکاتە 2. بۆ کۆک نین. %ـی Python نیشانەی ئەو ژمارەیە وەردەگرێت کە بەسەریدا دابەش دەکەیت، وەک  mod \bmod لە بیرکاریدا، MODـی Excel و modـی MATLAB: -7 % 3 دەکاتە 2. هەروەها //ـی Python ، ⌊a/n⌋\lfloor a/n \rfloor: -7 // 3 دەکاتە ⁦−3⁩، چونکە ⁦−2.33⁩… بەرەو خوار دەبێتە ⁦−3⁩.

remainders.pyPYTHONType in a terminalلە تێرمیناڵدا بینووسە
print(17 % 5, 17 // 5)     # remainder, then the floor of 17/5
print(-7 % 3, -7 // 3)     # the remainder takes the sign of 3
print(7 % -3, 7 // -3)     # ... and here the sign of -3
print(divmod(-7, 3))       # quotient and remainder together
print(-1 % 12)             # one hour before 12 o'clock
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

−7=−3×3+2-7 = -3 \times 3 + 2: the remainder 2 has the sign of 3.

−7=−3×3+2-7 = -3 \times 3 + 2: 2 نیشانەی 3ـی هەیە.

Lineدێڕی 5

The clock of the animation: one hour before 12 is 11.

کاتژمێرەکەی ئەنیمەیشنەکە: یەک کاتژمێر پێش ⁦12⁩ دەکاتە ⁦11⁩.

% and // in code: watch the negative numbers% و // لە کۆددا: ئاگاداری ژمارە سالبەکان بە

Java, C and JavaScript: the sign of the left numberJava، C و JavaScript: نیشانەی ژمارەی لای چەپ

Java, C, C# and JavaScript give % the sign of the left number, like MATLAB's rem. Java, C and C# also cut / on whole numbers toward 0 (JavaScript's / gives −2.33…). So in Java -7 % 3 is −1 and -7 / 3 is −2. For the maths answers Java has Math.floorMod and Math.floorDiv (Negative numbers and %, Dividing whole numbers, Dividing negative numbers).

Java، C، ⁦C#⁩ و JavaScript نیشانەی ژمارەی لای چەپ دەدەنە %، وەک remـی ⁦MATLAB. Java⁩، C و ⁦C#⁩ هەروەها / بۆ بەرەو 0 دەبڕن (/ـی ⁦JavaScript −2.33⁩… دەدات). کەواتە لە Javaـدا -7 % 3 دەکاتە ⁦−1⁩ و -7 / 3 دەکاتە ⁦−2⁩. بۆ وەڵامەکانی بیرکاری Java Math.floorMod و Math.floorDivـی هەیە (ژمارە سالبەکان و %، دابەشکردنی ژمارەی تەواو، دابەشکردنی ژمارە سالبەکان).

Remainders.javaJAVAType in a terminalلە تێرمیناڵدا بینووسە
public class Remainders {
    public static void main(String[] args) {
        System.out.println(17 % 5 + " " + 17 / 5);
        System.out.println(-7 % 3 + " " + -7 / 3);   // sign of the left number
        System.out.println(Math.floorMod(-7, 3) + " " + Math.floorDiv(-7, 3));
        System.out.println(Math.floorMod(-1, 12));
    }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

Java cuts −2.33… toward 0, so -7 / 3 is −2 and -7 % 3 is −1.

⁦Java −2.33⁩… بەرەو 0 دەبڕێت، بۆیە -7 / 3 دەکاتە ⁦−2⁩ و -7 % 3 دەکاتە ⁦−1⁩.

Lineدێڕی 5-6

floorMod and floorDiv give the maths answers, as Python does.

floorMod و floorDiv وەڵامەکانی بیرکاری دەدەن، وەک Python.

Two number lines from −9 to 0. Top: −7 / 3 = −2 and −7 % 3 = −1: two jumps of −3 reach −6, then −1 more reaches −7; the remainder has the sign of the left number (cut toward 0). Bottom: Math.floorDiv(−7, 3) = −3 and Math.floorMod(−7, 3) = 2: three jumps of −3 reach −9, then +2 comes back to −7; floor rounds down.دوو هێڵی ژمارە لە −9 تا 0. سەرەوە: −7 / 3 = −2 و −7 % 3 = −1: دوو بازی −3 دەگەنە −6، پاشان −1ـی تر دەگاتە −7؛ پاشماوەکە نیشانەی ژمارەی لای چەپی هەیە (بڕین بەرەو 0). خوارەوە: Math.floorDiv(−7, 3) = −3 و Math.floorMod(−7, 3) = 2: سێ بازی −3 دەگەنە −9، پاشان +2 دەگەڕێتەوە بۆ −7؛ floor بەرەو خوار دەبات.
Java's % and / cut toward 0; floorMod and floorDiv go down, as Python's % and // do.% و /ـی Java بەرەو 0 دەبڕن؛ floorMod و floorDiv بەرەو خوار دەچن، وەک % و //ـی Python.CêIT

Base subscripts: (1010)2(1010)_2, (F12)16(\text{F12})_{16}ژێرنووسی بنچینە: (1010)2(1010)_2، (F12)16(\text{F12})_{16}

A small number written low after a number names its base: (1010)2(1010)_2 is binary, (17)8(17)_8 octal, (259)10(259)_{10} decimal and (F12)16(\text{F12})_{16} hexadecimal; many books drop the brackets, 101021010_2. Read (1010)2(1010)_2 “one zero one zero, base two”, never “one thousand and ten”. Hexadecimal needs six more digits, A = 10 up to F = 15. Every digit must be smaller than the base, so a B in a base-2 number, as in the slip (652B)2(652\text{B})_2, shows that the base must be 16. In the place-value formula the base is usually called r (for radix) or b: N=dkrk+⋯+d1r+d0N = d_{k} r^{k} + \cdots + d_1 r + d_0.

ژمارەیەکی بچووک کە لە خوارەوەی دوای ژمارەیەک دەنووسرێت ناوی دەڵێت: (1010)2(1010)_2 ، (17)8(17)_8 ، (259)10(259)_{10} و (F12)16(\text{F12})_{16} ؛ زۆر کتێب کەوانەکان لادەبەن: 101021010_2. (1010)2(1010)_2 بخوێنەوە «یەک سفر یەک سفر، 2»، هەرگیز «هەزار و دە» نا. شەش زیاتری پێویستە: ⁦A = 10⁩ تا ⁦F = 15⁩. هەموو دەبێت لە بچووکتر بێت، بۆیە Bـێک لە ژمارەیەکی 2ـدا، وەک لە هەڵەی (652B)2(652\text{B})_2ـدا، پیشان دەدات کە دەبێت ⁦16⁩ بێت. لە زۆرجار r (لە radixـەوە) یان b ناو دەنرێت: N=dkrk+⋯+d1r+d0N = d_{k} r^{k} + \cdots + d_1 r + d_0.

Top left: (F12)₁₆ = 3858, with the digits F12 and the base 16 marked; say “F one two, base sixteen”. Top right: the hexadecimal digits after 9, A to F, with their values 10 to 15, and F = 15: 15 × 256 + 1 × 16 + 2 = 3858. Bottom: check that every digit is smaller than the base. (652B)₂ is crossed out, because base 2 allows only 0 and 1; an arrow leads to (652B)₁₆ = 25899, because B = 11 needs base 16.لە سەرەوەی چەپ: (F12)₁₆ = 3858، تاکژمارەکانی F12 و بنچینەی 16 نیشانە کراون؛ بخوێنەوە «F یەک دوو، بنچینەی 16». لە سەرەوەی ڕاست: تاکژمارەکانی شانزەیی لە دوای 9، A تا F، بە نرخەکانیان 10 تا 15. F = 15: 15 × 256 + 1 × 16 + 2 = 3858. لە خوارەوە: بپشکنە کە هەموو تاکژمارەیەک لە بنچینەکە بچووکترە. (652B)₂ خەتی بەسەردا هاتووە، چونکە بنچینەی 2 تەنیا 0 و 1 وەردەگرێت؛ تیرێک دەچێت بۆ (652B)₁₆ = 25899، چونکە B = 11 پێویستی بە بنچینەی 16 هەیە.
(F12)16(\text{F12})_{16}: digits, base and a check.(F12)16(\text{F12})_{16}: ، و پشکنینێک.CêIT

A bar repeats digits in every base: (23D.51EB8‾)16(23\text{D}.\overline{51\text{EB}8})_{16} means 23D.51EB851EB8… (Repeating decimals). Conversions are taught in Decimal, binary, octal and hexadecimal and The only table you need.

هێڵێکی سەرەوە لە هەموو دووپاتە دەکاتەوە: (23D.51EB8‾)16(23\text{D}.\overline{51\text{EB}8})_{16} واتە ⁦23D.51EB851EB8⁩… (ژمارەی دەیی دووپاتەبووەوە). لە دەیی، دووانی، هەشتی و شانزەیی و تاکە خشتەیەک کە پێویستتە فێر دەکرێت.

Prefixes in code: 0b, 0o, 0xپێشگرەکان لە کۆددا: 0b، 0o، 0x

Code cannot write subscripts, so it marks the base with a prefix: 0b1010 is binary, 0o12 octal (Python) and 0xA hexadecimal, in Python, Java and C alike. Other places use other marks: 0Ah with an h in assembly language, &HA in Visual Basic, #FF8800 for a colour in CSS and U+0041 for a Unicode code point. Windows error codes such as 0xc0000005 are hexadecimal numbers too (Write a useful ticket).

کۆد ناتوانێت بنووسێت، بۆیە بە نیشان دەدات: 0b1010 ، 0o12 ⁦(Python)⁩ و 0xA ، لە Python، Java و Cـدا وەک یەک. شوێنی تر نیشانەی تر بەکار دەهێنن: 0Ah بە h لە زمانی ئەسێمبلیدا، &HA لە Visual Basicـدا، #FF8800 بۆ ڕەنگێک لە CSSـدا و U+0041 بۆ Unicode. کۆدی هەڵەکانی Windows وەک 0xc0000005یش ژمارەی (تیکێتێکی بەسوود بنووسە).

Ten in the middle, with eight spellings around it: (1010)₂, binary in maths books; 1010₂, the short form; 0b1010, binary in Python and Java; (12)₈, octal in maths books; 0o12, octal in Python; (A)₁₆, hexadecimal in maths books; 0xA, hexadecimal in Python, Java and C; 0Ah, hexadecimal in assembly. A note at the bottom: careful, in Java and C, 012 is octal ten.دە لە ناوەڕاستدا و هەشت شێوەی نووسین بە دەوریدا: (1010)₂، دووانی لە کتێبی بیرکاریدا؛ 1010₂، شێوەی کورت؛ 0b1010، دووانی لە Python و Javaـدا؛ (12)₈، هەشتی لە کتێبی بیرکاریدا؛ 0o12، هەشتی لە Pythonـدا؛ (A)₁₆، شانزەیی لە کتێبی بیرکاریدا؛ 0xA، شانزەیی لە Python، Java و Cـدا؛ 0Ah، شانزەیی لە ئەسێمبلیدا. تێبینییەک لە خوارەوە: ئاگاداربە، لە Java و Cـدا 012 بە هەشتی دەیە.
Ten, written eight ways.دە، بە هەشت شێوە نووسراوە.CêIT
bases.pyPYTHONType in a terminalلە تێرمیناڵدا بینووسە
n = 0b1010                    # binary literal
print(n, 0o12, 0xA, 10)       # four spellings, one number
print(bin(42), oct(42), hex(42))
print(int("101010", 2), int("2A", 16), int("52", 8))
print(f"{255:b} {255:o} {255:x} {255:X}")
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3-4

bin, oct and hex write a number with a prefix; int(text, base) reads it back.

bin، oct و hex ژمارەیەک بە دەنووسن؛ int(text, base) دەیخوێنێتەوە.

Prefixes in code: 0b, 0o, 0xپێشگرەکان لە کۆددا: 0b، 0o، 0x

A leading zero: twelve, ten or an error?سفرێکی پێشەوە: دوازدە، دە یان هەڵە؟

On paper, a zero in front changes nothing: 012 is twelve. In Java, C and C++, a number that starts with 0 is octal, so 012 is ten and 017 is fifteen. Python 3 refuses such numbers and asks for the clear prefix 0o.

لەسەر کاغەز سفرێک لە پێشەوە هیچ ناگۆڕێت: ⁦012⁩ دوازدەیە. لە Java، C و ⁦C++⁩ـدا ژمارەیەک کە بە 0 دەست پێبکات ، بۆیە 012 دەیە و 017 پازدە. ⁦Python 3⁩ ئەم جۆرە ژمارانە ڕەت دەکاتەوە و ڕوونی 0o داوا دەکات.

Three cards. On paper: 012 = 12, a leading zero changes nothing. Java, C, C++: 012 = 10, a leading 0 means octal. Python 3: 012 gives an error; write 0o12 for octal.سێ کارت. لەسەر کاغەز: 012 = 12، سفری پێشەوە هیچ ناگۆڕێت. Java، C، C++: 012 = 10، سفری پێشەوە واتە هەشتی. Python 3: 012 هەڵە دەدات؛ بۆ هەشتی 0o12 بنووسە.
One written number, three readings.یەک ژمارەی نووسراو، سێ خوێندنەوە.CêIT
Literals.javaJAVAType in a terminalلە تێرمیناڵدا بینووسە
public class Literals {
    public static void main(String[] args) {
        System.out.println(0b1010 + " " + 0xA + " " + 012);  // 012 starts with 0: octal!
        System.out.println(017);
        System.out.println(Integer.toBinaryString(42) + " " + Integer.toHexString(42));
    }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3-4

012 and 017 start with 0, so Java reads them in base 8: 10 and 15.

012 و 017 بە 0 دەست پێدەکەن، بۆیە Java بە 8 دەیانخوێنێتەوە: ⁦10⁩ و ⁦15⁩.

b, B, Ki and powers of twob، B، Ki و توانەکانی 2

Powers of two count possibilities: n bits give 2n2^n patterns (How many patterns do N bits give?). One byte has 28=2562^8 = 256 patterns, 16 bits 216=65 5362^{16} = 65\,536, and an IPv4 address has 32 bits, so there are 232≈4.32^{32} \approx 4.3 billion addresses. Subnetting uses the same powers: S borrowed bits give 2S2^S subnets (Borrowing host bits in the Computer Networks course). A logic program that tries every true/false choice for 25 facts checks 225≈33.52^{25} \approx 33.5 million cases (Model checking). 210=10242^{10} = 1024 is close to 1000, which is why computers have two prefixes: k = 1000 and Ki = 1024. Copy the letters exactly: b is a bit, B a byte (Prefixes are powers of ten, b or B).

2 ژمارەی هەڵبژاردە جیاوازەکان دەژمێرن: n ، 2n2^n شێوەی جیاواز دەدات (N بیت چەند شێوە دەدات؟). یەک 28=2562^8 = 256 شێوەی هەیە، ⁦16⁩ 216=65 5362^{16} = 65\,536 و ناونیشانێکی ⁦IPv4 32⁩ ، بۆیە 232≈4.32^{32} \approx 4.3 ملیار ناونیشان هەیە. هەمان بەکار دەهێنێت: S قەرزکراو 2S2^S دەدات (قەرزکردنی بیتەکانی میوانگر لە کۆرسی کۆمپیوتەردا). لۆجیکی کە هەموو هەڵبژاردنێکی ڕاست/هەڵە بۆ ⁦25⁩ ڕاستی تاقی دەکاتەوە 225≈33.52^{25} \approx 33.5 ملیۆن بار دەپشکنێت (پشکنینی مۆدێل). 210=10242^{10} = 1024 نزیکە لە ⁦1000⁩، بۆیە دوو هەیە: ⁦k = 1000⁩ و ⁦Ki = 1024⁩. پیتەکان وەک خۆیان بنووسە: b و B (پێشگرەکان توانەکانی ⁦10⁩ـن، بیت یان بایت).

Title: n bits give 2ⁿ patterns. Five bars, each longer than the one before: 2⁸ = 256, one byte, 256 patterns; 2¹⁰ = 1024 ≈ 10³, Ki (kibi) = 1024 while k (kilo) = 1000; 2¹⁶ = 65 536, 16 bits; 2³² ≈ 4.3 × 10⁹, about 4.3 billion, all IPv4 addresses; 2⁶⁴ ≈ 1.8 × 10¹⁹, a 64-bit number.ناونیشان: n بیت، 2ⁿ شێوەی جیاواز دەدات. پێنج ستوون، هەریەکەیان لەوەی پێشوو درێژترە: 2⁸ = 256، یەک بایت، 256 شێوە؛ 2¹⁰ = 1024 ≈ 10³، Ki (کیبی) = 1024 بەڵام k (کیلۆ) = 1000؛ 2¹⁶ = 65 536، 16 بیت؛ 2³² ≈ 4.3 × 10⁹، نزیکەی 4.3 ملیار، هەموو ناونیشانەکانی IPv4؛ 2⁶⁴ ≈ 1.8 × 10¹⁹، ژمارەیەکی 64 بیتی.
Powers of two that computing books use all the time.ئەو 2 کە کتێبەکانی هەمیشە بەکاریان دەهێنن.CêIT

Big-O: O(n)O(n), O(log⁡n)O(\log n), O(n2)O(n^2), and Θ and Ωنیشانەی O-ی گەورە: O(n)O(n)، O(log⁡n)O(\log n)، O(n2)O(n^2)، هەروەها Θ و Ω

Big-O describes how the work of an algorithm, the time it takes or the memory it needs, grows with the input size n. O(n2)O(n^2) is read “big-O of n squared” or “order n squared” (the O stands for “order”: Why one letter?): the work grows at most like n2n^2. The common orders are O(1)O(1) (constant), O(log⁡n)O(\log n), O(n)O(n), O(nlog⁡n)O(n \log n), O(n2)O(n^2) and O(2n)O(2^n). The = in 3n2+5n+2=O(n2)3n^2 + 5n + 2 = O(n^2) works one way only: it means “is at most of the order of”, so 3n+4=O(n2)3n + 4 = O(n^2) is true as well, but nobody writes O(n2)=3n2+5n+2O(n^2) = 3n^2 + 5n + 2. Some books write a set instead: f∈O(n2)f \in O(n^2).

وەسفی ئەوە دەکات کە کاری ، واتە ئەو کاتەی دەیخایەنێت یان ئەو پێویستیەتی، لەگەڵ قەبارەی ، n، چۆن گەورە دەبێت. O(n2)O(n^2) بە ئینگلیزی big-O of n squared یان order n squared دەخوێنرێتەوە (یەک شێوەی کوردی: «O-ی گەورەی n دووجا»؛ O بۆ «پلە»یە، order: بۆچی یەک پیت؟): کارەکە زۆرترین وەک n2n^2 گەورە دەبێت. پلە ناسراوەکان: O(1)O(1) ()، O(log⁡n)O(\log n)، O(n)O(n)، O(nlog⁡n)O(n \log n)، O(n2)O(n^2) و O(2n)O(2^n). هێمای = لە 3n2+5n+2=O(n2)3n^2 + 5n + 2 = O(n^2)ـدا تەنیا بە یەک ئاڕاستە کار دەکات: واتە «زۆرترین لە پلەی … دایە»، بۆیە 3n+4=O(n2)3n + 4 = O(n^2)ـیش ڕاستە، بەڵام کەس O(n2)=3n2+5n+2O(n^2) = 3n^2 + 5n + 2 نانووسێت. هەندێک کتێب لەبری ئەوە دەنووسن: f∈O(n2)f \in O(n^2).

Growth curves for n from 0 to 16, with steps up to 64 on the vertical axis: O(1) flat, O(log n) rising very slowly, O(n) a straight line, O(n²) curving up steeply and leaving the chart at n = 8, O(2ⁿ) dashed, leaving it before n = 6. A box gives the values for n = 16: O(1) 1, O(log n) 4, O(n) 16, O(n²) 256, O(2ⁿ) 65 536.چەماوەکانی گەشە بۆ n لە 0 تا 16، هەنگاو تا 64 لەسەر تەوەرە ستوونییەکە: O(1) ڕاست، O(log n) زۆر هێواش بەرز دەبێتەوە، O(n) هێڵێکی ڕاست، O(n²) بە خێرایی بەرز دەبێتەوە و لە n = 8 لە وێنەکە دەردەچێت، O(2ⁿ) پچڕپچڕ، پێش n = 6 دەردەچێت. سندووقێک نرخەکان بۆ n = 16 دەدات: O(1) 1، O(log n) 4، O(n) 16، O(n²) 256، O(2ⁿ) 65 536.
How fast O(1)O(1), O(log⁡n)O(\log n), O(n)O(n), O(n2)O(n^2) and O(2n)O(2^n) grow.O(1)O(1)، O(log⁡n)O(\log n)، O(n)O(n)، O(n2)O(n^2) و O(2n)O(2^n) چەند خێرا گەورە دەبن.CêIT

Two relatives: Ω(n2)\Omega(n^2), “big-Omega”, means at least of that order (a lower bound), and Θ(n2)\Theta(n^2), “big-Theta”, means exactly that order. So Ω has a third job here, after the ohm and the sample space (One letter, many jobs). In big-O the base of the log does not matter (log x with no base). The idea itself: Big-O notation in one screen and How fast is fast?

دوو خزم: Ω(n2)\Omega(n^2)، big-Omega، واتە لانیکەم لەو پلەیەدایە (سنووری خوارەوە) و Θ(n2)\Theta(n^2)، big-Theta، واتە ڕێک لەو پلەیەدایە. کەواتە Ω لێرەدا کاری سێیەمی هەیە، لە دوای ئۆم و (یەک پیت، چەند کار). لە گرنگ نییە (log x بەبێ بنچینە). خودی بیرۆکەکە: نیشانەی O-ی گەورە لە یەک شاشەدا و خێرا چەندە خێرایە؟

log⁡2n\log_2 n: how many halvings?log⁡2n\log_2 n: چەند جار نیوەکردن؟

Each look of a binary search halves the part of the sorted list that is still possible, so the number of looks is a binary logarithm: at most ⌊log⁡2n⌋+1\lfloor \log_2 n \rfloor + 1, the same as ⌈log⁡2(n+1)⌉\lceil \log_2 (n+1) \rceil. That is the O(log⁡n)O(\log n) of the last screen. Python's math.log2 gives the logarithm, and math.floor the floor (log on calculators, in Excel and in code, How many steps?).

هەر سەیرکردنێکی ئەو بەشەی ڕیزکراوەکە نیوە دەکات کە هێشتا دەشێت وەڵامەکەی تێدا بێت، بۆیە ژمارەی سەیرکردنەکان : زۆرترین ⌊log⁡2n⌋+1\lfloor \log_2 n \rfloor + 1، کە هەمان ⌈log⁡2(n+1)⌉\lceil \log_2 (n+1) \rceilـە. ئەمە هەمان O(log⁡n)O(\log n)ـی شاشەی پێشووە. math.log2ـی Python دەدات و math.floor بەرەو خوار دەیبات (log لەسەر حاسیبە، لە Excel و لە کۆددا، چەند هەنگاو؟).

steps.pyPYTHONType in a terminalلە تێرمیناڵدا بینووسە
import math

for n in [15, 1000, 1_000_000, 2**30]:
    looks = math.floor(math.log2(n)) + 1     # binary search, worst case
    print(f"{n:>13,} items: at most {looks} looks")
Four rows of 15 boxes, one row per look of a binary search. Look 1: all 15 boxes are still possible. Look 2: 7 boxes. Look 3: 3 boxes. Look 4: 1 box; the others are grey. A note says 15, 7, 3, 1: at most 4 looks for 15 items, and a million sorted items need at most 20 looks, a billion 30.چوار ڕیزی 15 سندووق، هەر ڕیزێک بۆ یەک سەیرکردنی گەڕانی دووانی. سەیرکردنی 1: هەموو 15 سندووقەکە هێشتا ئەگەریان هەیە. سەیرکردنی 2: 7 سندووق. سەیرکردنی 3: 3 سندووق. سەیرکردنی 4: 1 سندووق؛ ئەوانی تر خۆڵەمێشین. تێبینییەک دەڵێت 15، 7، 3، 1: زۆرترین 4 سەیرکردن بۆ 15 دانە و ملیۆنێک دانەی ڕیزکراو زۆرترین 20 سەیرکردن و ملیارێک 30 پێویستە.
15→7→3→115 \to 7 \to 3 \to 1: ⌊log⁡215⌋+1=4\lfloor \log_2 15 \rfloor + 1 = 4 looks.15→7→3→115 \to 7 \to 3 \to 1: ⌊log⁡215⌋+1=4\lfloor \log_2 15 \rfloor + 1 = 4 سەیرکردن.CêIT

Maths signs and code signsهێماکانی بیرکاری و هێماکانی کۆد

Code writes maths with keyboard signs, and one sign can mean different things. Python writes powers as **; its ^ is XOR, exclusive or (XOR: one or the other, not both), as in Java, which has no power sign and calls Math.pow(2, 3) (it prints 8.0). MATLAB and Excel use ^ for powers. Equality is asked with == (Excel: =); not-equal is !=, in MATLAB ~= and in Excel <>. A single = stores a value; pseudocode writes x ← 5, and some books x := 5 (“=” and “==” in programming, Pseudocode).

کۆد بیرکاری بە نیشانەکانی دەنووسێت و یەک نیشانە دەتوانێت واتای جیاوازی هەبێت. Python بە ** دەنووسێت؛ ^ـی ئەو XORـە (XOR: یەکێکیان، نەک هەردووکیان)، وەک Java کە نیشانەی نییە و Math.pow(2, 3) بانگ دەکات (8.0 چاپ دەکات). MATLAB و Excel ^ بۆ بەکار دەهێنن. یەکسانی بە == دەپرسرێت (Excel: =)؛ یەکسان نەبوون !=ـە، لە MATLABـدا ~= و لە Excelـدا <>. یەک = نرخێک هەڵدەگرێت؛ دەنووسێت x ← 5 و هەندێک کتێب x := 5 («=» و «==» لە بەرنامەسازیدا، نیمچەکۆد).

A table with the columns idea, maths, Python, Java, MATLAB and Excel. Power: xⁿ, x**n, Math.pow(x, n), x^n, =x^n. XOR, bit by bit: ⊕, a ^ b, a ^ b, bitxor(a, b), =BITXOR(a, b). Equal?: =, x == y in Python, Java and MATLAB, =A1=B1 in Excel. Not equal: ≠, x != y, x != y, x ~= y, =A1<>B1. Store a value: x ← 5, x = 5, x = 5;, x = 5, type it in a cell. Remainder: a mod n, a % n, Math.floorMod(a, n), mod(a, n), =MOD(a, n). Floor division: ⌊a/n⌋, a // n, Math.floorDiv(a, n), floor(a/n), =INT(a/n). Bottom: one sign, two meanings: ^ is a power in MATLAB and Excel but XOR in Python and Java.خشتەیەک بە ستوونەکانی بیرۆکە، بیرکاری، Python، Java، MATLAB و Excel. توان: xⁿ، x**n، Math.pow(x, n)، x^n، =x^n. XOR، بیت بە بیت: ⊕، a ^ b، a ^ b، bitxor(a, b)، =BITXOR(a, b). یەکسانە؟: =، x == y لە Python، Java و MATLABـدا، =A1=B1 لە Excelـدا. یەکسان نییە: ≠، x != y، x != y، x ~= y، =A1<>B1. دانانی نرخ: x ← 5، x = 5، x = 5;، x = 5، لە خانەیەکدا بینووسە. پاشماوە: a mod n، a % n، Math.floorMod(a, n)، mod(a, n)، =MOD(a, n). دابەشکردنی بەرەو خوار: ⌊a/n⌋، a // n، Math.floorDiv(a, n)، floor(a/n)، =INT(a/n). لە خوارەوە: ^ لە MATLAB و Excelـدا بەرزکردنەوە بۆ توانە، بەڵام لە Python و Javaـدا XORـە.
One idea, five ways to write it.یەک بیرۆکە، پێنج شێوەی نووسین.CêIT

Maths signs and code signsهێماکانی بیرکاری و هێماکانی کۆد

Saying code operators in Kurdishخوێندنەوەی کارپێکەرەکان بە کوردی

A Kurdish MATLAB guide reads the comparison and logic operators aloud like this. The same readings work for Python, Java and Excel.

ڕێبەرێکی کوردیی MATLAB و بەم شێوەیە دەخوێنێتەوە. هەمان خوێندنەوە بۆ Python، Java و Excelـیش دەگونجێت.

OperatorSay it (EN)بە ئینگلیزیSay it (Kurdish)بە کوردی
a == ba is equal to ba یەکسانە بە b«a یەکسانە بە b»
a ~= ba is not equal to ba یەکسان نییە بە b (Python, Java: !=)«a یەکسان نییە بە b» (Python، Java: !=)
a < ba is less than ba بچووکترە لە b«a بچووکترە لە b»
a > ba is greater than ba گەورەترە لە b«a گەورەترە لە b»
a & ba and ba و b«a و b»
a | ba or ba یان b«a یان b»
x ← 5store 5 in x5 بخە ناو x«5 بخە ناو x»
operators.pyPYTHONType in a terminalلە تێرمیناڵدا بینووسە
print(2 ** 3, 2 ^ 3)    # power, then XOR
print(5 ^ 3)            # 101 XOR 011 = 110
print(7 != 3, 7 == 7.0)
x = 5                   # = stores a value
x = x + 1
print(x == 6)           # == asks a question
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1-2

** is the power; ^ is XOR: 5 is 101, 3 is 011, and 101 XOR 011 = 110, which is 6.

** ؛ ^ XORـە: 5 بریتییە لە ⁦101⁩، 3 لە ⁦011⁩ و ⁦101 XOR 011 = 110⁩، کە 6ـە.

Lineدێڕی 4-6

= stores, == asks: x == 6 gives True.

= هەڵدەگرێت، == دەپرسێت: x == 6 دەدات True.

Indexes: x1x_1, v(1) or v[0]?ئیندێکسەکان: x1x_1، v(1) یان v[0]؟

Maths counts from 1: x1x_1 is the first value. MATLAB and Excel do the same: v(1) is the first element and A1 the first cell. Python, Java, C and many other languages count from 0, so the first element is v[0] and the last of four is v[3]. The same matrix entry a23a_{23} is A(2,3) in MATLAB but A[1][2] in Python. Forgetting this shift by one is the classic off-by-one error.

بیرکاری لە 1ـەوە دەژمێرێت: x1x_1 یەکەم نرخە. MATLAB و Excelـیش هەروا: v(1) یەکەم و ⁦A1⁩ یەکەم خانە. Python، Java، C و زۆر زمانی تر لە 0ـەوە دەژمێرن، بۆیە یەکەم v[0]ـە و دوایینی چوار دانە v[3]. هەمان ژمارەی ، a23a_{23}، لە MATLABـدا A(2,3)ـە بەڵام لە Pythonـدا A[1][2]. لەبیرکردنی ئەم یەک جیاوازییە هەڵەی ناسراوی «یەک زیاد یان یەک کەم»ـە (off-by-one error).

Four boxes hold 8, 3, 5 and 6; the first box is orange. Above them, maths counts from 1: x₁, x₂, x₃, x₄; MATLAB and Excel count from 1: v(1) to v(4). Below them, Python, Java and C count from 0: v[0] to v[3]. Bottom: the first element is x₁ in maths, v(1) in MATLAB and v[0] in Python.چوار سندووق 8، 3، 5 و 6ـیان تێدایە؛ سندووقی یەکەم پرتەقاڵییە. لە سەرەوە، بیرکاری لە 1ـەوە دەژمێرێت: x₁، x₂، x₃، x₄؛ MATLAB و Excel لە 1ـەوە دەژمێرن: v(1) تا v(4). لە خوارەوە، Python، Java و C لە 0ـەوە دەژمێرن: v[0] تا v[3]. لە کۆتاییدا: یەکەم دانە x₁ـە لە بیرکاریدا، v(1) لە MATLABـدا و v[0] لە Pythonـدا.
From 1 or from 0: the same four values.لە 1ـەوە یان لە 0ـەوە: هەمان چوار نرخ.CêIT
indexes.pyPYTHONType in a terminalلە تێرمیناڵدا بینووسە
marks = [8, 3, 5, 6]          # x1, x2, x3, x4 in maths
print(marks[0], marks[3])     # the first and the last: indexes 0 and 3
print(len(marks))
A = [[7, -2, 5],
     [4, 9, -1]]
print(A[1][2])                # a23 in maths: row 2, column 3
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 6

Row 2 is index 1 and column 3 is index 2.

ڕیزی 2 1ـە و ستوونی 3 2.

σ, π and ⋈ in databasesσ، π و ⋈ لە بنکەدراوەدا

Database books reuse Greek letters with new meanings. σdept=CS(Student)\sigma_{\text{dept} = \text{CS}}(\text{Student}) is read “select the rows of Student where dept is CS” (Selection σ: choose rows); πname(Student)\pi_{\text{name}}(\text{Student}) is “project Student on name”, keeping only that column (Projection π). ρ\rho renames a table, ⋈\bowtie (“bowtie”) joins two tables, ÷\div answers “for all” questions, ⟕ is a left outer join that keeps every row of the left table (Outer joins), and ×, ∪, ∩ and − work as with sets. In a statistics book the same σ is the standard deviation, and π is 3.14159….

کتێبەکانی پیتە یۆنانییەکان بە واتای نوێ بەکار دەهێننەوە. σdept=CS(Student)\sigma_{\text{dept} = \text{CS}}(\text{Student}) دەخوێنرێتەوە «ئەو ڕیزانەی Student هەڵبژێرە کە deptـیان CSـە» (هەڵبژاردن σ)؛ πname(Student)\pi_{\text{name}}(\text{Student}) واتە «تەنیا ستوونی name لە Student بهێڵەرەوە» (دەرهێنانی ستوون π). ρ\rho ناوی خشتەیەک دەگۆڕێت، ⋈\bowtie (bowtie) دوو خشتە پێکەوە دەبەستێت ()، ÷\div وەڵامی پرسیاری «بۆ هەموو» دەداتەوە، ⟕ چەپە و هەموو ڕیزەکانی خشتەی چەپ دەهێڵێتەوە (لێکبەستنە دەرەکییەکان) و ×، ∪، ∩ و − وەک لە کار دەکەن. لە کتێبێکی هەمان σ و π ژمارەی ⁦3.14159⁩…ـە.

A table with two columns: in maths and statistics, and in relational algebra (databases). σ: standard deviation; σ with dept = CS below it, applied to Student, selection, keep some rows. π: 3.14159…; π with name below it, applied to Student, projection, keep some columns. ρ: the correlation of a population; ρ with S1 below it, applied to Student, rename. ÷: divided by; A ÷ B, division, “for all” questions. ⋈: no maths meaning; R ⋈ S, join, rows that belong together.خشتەیەک بە دوو ستوون: لە بیرکاری و ئاماردا و لە جەبری پەیوەندیداردا. σ: لادانی پێوانەیی؛ σ بە dept = CS لە ژێریدا، لەسەر Student، هەڵبژاردن، هەندێک ڕیز دەهێڵێتەوە. π: 3.14159…؛ π بە name لە ژێریدا، لەسەر Student، دەرهێنانی ستوون، هەندێک ستوون دەهێڵێتەوە. ρ: پەیوەستیی کۆمەڵگە؛ ρ بە S1 لە ژێریدا، لەسەر Student، ناونانەوە. ÷: دابەش بەسەر؛ A ÷ B، دابەشکردن، پرسیاری «بۆ هەموو». ⋈: هیچ واتایەکی بیرکاری نییە؛ R ⋈ S، لێکبەستن، ئەو ڕیزانەی پێکەوە دەگونجێن.
The same Greek letters, other jobs in a database.هەمان پیتە یۆنانییەکان، کاری تر لە .CêIT

Common mistakesهەڵە باوەکان

MistakeهەڵەWhy it is wrongبۆچی هەڵەیەDo thisئەمە بکە
Expecting -7 % 3 to give the same answer in every languageچاوەڕوانیی هەمان وەڵام بۆ -7 % 3 لە هەموو زمانێکداPython gives 2, Java and C give −1⁦Python 2⁩ دەدات، Java و ⁦C −1⁩Use Math.floorMod in Java for the maths answerلە Javaـدا Math.floorMod بەکار بهێنە بۆ وەڵامی بیرکاری
Reading (1010)2(1010)_2 as one thousand and tenخوێندنەوەی (1010)2(1010)_2 وەک هەزار و دەThe subscript 2 says binary 2 دەڵێت “one zero one zero, base two” = 10«یەک سفر یەک سفر، 2» = ⁦10⁩
Writing (652B)2(652\text{B})_2نووسینی (652B)2(652\text{B})_2Base 2 has only 0 and 1 2 تەنیا 0 و 1ـی هەیەCheck the digits: (652B)16(652\text{B})_{16} بپشکنە: (652B)16(652\text{B})_{16}
Writing 012 in Java and expecting twelveنووسینی 012 لە Javaـدا و چاوەڕوانیی دوازدەA leading 0 means octal: tenسفری پێشەوە واتە : دەWrite 12; for octal write it on purpose12 بنووسە؛ بۆ بە ئەنقەست بینووسە
2 ^ 3 for a power in Python or Java2 ^ 3 بۆ لە Python یان Javaـدا^ is XOR there: it gives 1لەوێ ^ XORـە: 1 دەدات2 ** 3, Math.pow(2, 3)2 ** 3، Math.pow(2, 3)
Reading f=O(n2)f = O(n^2) as an equationخوێندنەوەی f=O(n2)f = O(n^2) وەک The = works one way: “is at most of the order”= تەنیا بە یەک ئاڕاستە کار دەکات: «زۆرترین لەو پلەیەدایە»Never turn it round; or write f∈O(n2)f \in O(n^2)هەرگیز پێچەوانەی مەکەرەوە؛ یان f∈O(n2)f \in O(n^2) بنووسە
Using v[1] for the first element in Pythonبەکارهێنانی v[1] بۆ یەکەم لە PythonـداPython counts from 0Python لە 0ـەوە دەژمێرێتx1x_1 = v(1) in MATLAB = v[0] in Pythonx1x_1 = v(1) لە MATLAB = v[0] لە Python
Reading σ in a database book as a standard deviationخوێندنەوەی σ لە کتێبی وەک There it selects rowsلەوێ ڕیز هەڵدەبژێرێتAsk which book you are readingبزانە کام کتێب دەخوێنیتەوە

Practiceڕاهێنان

ExerciseڕاهێنانMaths into Python and MATLABلە بیرکارییەوە بۆ Python و MATLAB

Write each one in Python and in MATLAB: (a) 2102^{10} (b) 17 mod 517 \bmod 5 (c) ⌊17/5⌋\lfloor 17/5 \rfloor (d) “is x not equal to 0?” (e) the first element of a list v.

هەر یەکەیان بە Python و بە MATLAB بنووسە: ⁦(a)⁩ 2102^{10} ⁦(b)⁩ 17 mod 517 \bmod 5 ⁦(c)⁩ ⌊17/5⌋\lfloor 17/5 \rfloor ⁦(d)⁩ «ئایا x یەکسان نییە بە 0؟» ⁦(e)⁩ یەکەم لیستی v.

Show answerوەڵامەکە پیشان بدە
MathsبیرکاریPythonMATLAB
2102^{10}2 ** 102^10
17 mod 517 \bmod 517 % 5mod(17, 5)
⌊17/5⌋\lfloor 17/5 \rfloor17 // 5floor(17/5)
x≠0x \ne 0x != 0x ~= 0
v1v_1v[0]v(1)
ExerciseڕاهێنانRead three big-O statementsسێ ڕستەی نیشانەی O-ی گەورە بخوێنەوە

Read each statement aloud and say what it means: (a) binary search is O(log⁡n)O(\log n) (b) bubble sort is O(n2)O(n^2) (c) trying every sequence of d actions with b choices each is O(bd)O(b^d).

هەر ڕستەیەک بە دەنگی بەرز بخوێنەوە و بڵێ واتای چییە: ⁦(a)⁩ O(log⁡n)O(\log n)ـە ⁦(b)⁩ O(n2)O(n^2)ـە ⁦(c)⁩ تاقیکردنەوەی هەموو زنجیرەیەکی d کار کە هەر جارێک b هەڵبژاردەی هەیە O(bd)O(b^d)ـە.

Show answerوەڵامەکە پیشان بدە
  • (a) “big-O of log n”: doubling the list adds only one look.
  • (b) “order n squared”: twice the data, about four times the work.
  • (c) “big-O of b to the d”: exponential; each extra step multiplies the work by b.
  • ⁦(a)⁩ «O-ی گەورەی log n»: دوو هێندەکردنی تەنیا یەک سەیرکردن زیاد دەکات.
  • ⁦(b)⁩ «O-ی گەورەی n دووجا» (order n squared): دوو هێندە ، نزیکەی چوار هێندە کار.
  • ⁦(c)⁩ «O-ی گەورەی b بە d»: هەر هەنگاوێکی زیادە کارەکە b جار زیاتر دەکات.
ExerciseڕاهێنانConvert the base notationsشێوەکانی نووسینی بنچینە بگۆڕە

Write each number in decimal: (a) (1011)2(1011)_2 (b) 0x2A (c) 0o17 (d) (FF)16(\text{FF})_{16} (e) 012 in Java.

هەر ژمارەیەک بە بنووسە: ⁦(a)⁩ (1011)2(1011)_2 ⁦(b)⁩ 0x2A ⁦(c)⁩ 0o17 ⁦(d)⁩ (FF)16(\text{FF})_{16} ⁦(e)⁩ 012 لە Javaـدا.

Show answerوەڵامەکە پیشان بدە
(a) (1011)2=8+0+2+1=11(b) 0x2A=2×16+10=42(c) 0o17=1×8+7=15(d) (FF)16=15×16+15=255(e) 012=1×8+2=10\begin{aligned} \text{(a)}\ & (1011)_2 = 8 + 0 + 2 + 1 = 11 \\ \text{(b)}\ & \texttt{0x2A} = 2 \times 16 + 10 = 42 \\ \text{(c)}\ & \texttt{0o17} = 1 \times 8 + 7 = 15 \\ \text{(d)}\ & (\text{FF})_{16} = 15 \times 16 + 15 = 255 \\ \text{(e)}\ & \texttt{012} = 1 \times 8 + 2 = 10 \end{aligned}

In (e) the leading 0 makes Java read the digits in base 8.

لە ⁦(e)⁩ـدا سفری پێشەوە وا دەکات Java بە 8 بخوێنێتەوە.

Summaryپوختە

  • a mod na \bmod n is the remainder; a≡b(modn)a \equiv b \pmod{n} means the same remainder; div, // and ⌊a/n⌋\lfloor a/n \rfloor give the quotient.
  • % with negative numbers: Python, Excel MOD and MATLAB mod follow the divisor; Java, C and MATLAB rem follow the left number.
  • Bases: (1010)2(1010)_2, 0b1010, 0o12, 0xA; every digit is smaller than the base; a leading 0 is octal in Java and C.
  • n bits give 2n2^n patterns; 210=10242^{10} = 1024 is Ki; b is a bit, B a byte.
  • O(n2)O(n^2) “order n squared”: an upper bound, a one-way =; Ω a lower bound, Θ the exact order; binary search needs ⌊log⁡2n⌋+1\lfloor \log_2 n \rfloor + 1 looks.
  • ** vs ^, == vs =, != ~= <>, ← and :=; indexes from 1 in maths and MATLAB, from 0 in Python and Java; σ π ⋈ in databases.
  • All these signs, with their readings, are in the Symbol dictionary: Notation in computing.
  • a mod na \bmod n ؛ a≡b(modn)a \equiv b \pmod{n} واتە هەمان ؛ div، // و ⌊a/n⌋\lfloor a/n \rfloor ئەنجامی دەدەن.
  • % لەگەڵ : Python، MODـی Excel و modـی MATLAB شوێن دابەشکەرەکە دەکەون؛ Java، C و remـی MATLAB شوێن ژمارەی لای چەپ دەکەون.
  • : (1010)2(1010)_2، 0b1010، 0o12، 0xA؛ هەموو لە بچووکترە؛ سفری پێشەوە لە Java و Cـدا .
  • n ، 2n2^n شێوە دەدات؛ 210=10242^{10} = 1024 Kiـیە؛ b و B .
  • O(n2)O(n^2) «O-ی گەورەی n دووجا»: سنووری سەرەوە، = بە یەک ئاڕاستە؛ Ω سنووری خوارەوە، Θ پلەی ڕێک؛ ⌊log⁡2n⌋+1\lfloor \log_2 n \rfloor + 1 سەیرکردنی پێویستە.
  • ** بەرامبەر ^، == بەرامبەر =، != ~= <>، ← و :=؛ لە بیرکاری و MATLABـدا لە 1ـەوە، لە Python و Javaـدا لە 0ـەوە؛ σ π ⋈ لە .
  • هەموو ئەم نیشانانە، لەگەڵ خوێندنەوەکانیان، لە فەرهەنگی هەن: هێماکان لە کۆمپیوتەردا.
Review questionsپرسیارەکانی پێداچوونەوە
How do you read 17≡2(mod5)17 \equiv 2 \pmod{5}?17≡2(mod5)17 \equiv 2 \pmod{5} چۆن دەخوێنیتەوە؟

“17 is congruent to 2 modulo 5”: both leave the remainder 2 when divided by 5.

«⁦17⁩ و 2 یەکسانە بەسەر 5ـدا» (17 is congruent to 2 modulo 5): هەردووکیان لە بەسەر 5ـدا 2 دەدەن.

What is 0xFF?0xFF چییە؟

The hexadecimal number FF: 15×16+15=25515 \times 16 + 15 = 255.

ژمارەی FF: 15×16+15=25515 \times 16 + 15 = 255.

Why does v[0] hold x1x_1 in Python?بۆچی لە Pythonـدا v[0] x1x_1 هەڵدەگرێت؟

Python counts its indexes from 0, while maths counts from 1.

Python لە 0ـەوە دەژمێرێت، بەڵام بیرکاری لە 1ـەوە.

Lesson complete!وانەکە تەواو بوو!

Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.

Key termsزاراوە سەرەکییەکان

Next lessonوانەی داهاتوو

Typing Mathematics: Keyboards, Word, LaTeX and Unicodeچۆن بیرکاری بنووسیت: کیبۆرد، Word، LaTeX و Unicode

Related lecturesوانە پەیوەندیدارەکان

References and further readingسەرچاوەکان و خوێندنەوەی زیاتر

This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.

Appearanceڕووکار

Modeدۆخ
Styleشێواز
Coloursڕەنگەکان

Saved on this device only.تەنیا لەسەر ئەم ئامێرە پاشەکەوت دەکرێت.