Expecco Code Snippets/en: Unterschied zwischen den Versionen

Aus expecco Wiki (Version 2.x)
Zur Navigation springen Zur Suche springen
Zeile 1: Zeile 1:
== Code Snippets for Common Tasks ==
== Code Snippets for Common Tasks ==

This page provides code snippets for common tasks. You can copy-paste these snippets into the code editor and modify as appropriate. You can also paste them into a Workspace window and execute them there. Finally, you may also find those snippets via the Method Finder, when entering the desired result value.


=== Bits & Bytes ===
=== Bits & Bytes ===

Version vom 18. September 2020, 13:19 Uhr

Code Snippets for Common Tasks[Bearbeiten]

This page provides code snippets for common tasks. You can copy-paste these snippets into the code editor and modify as appropriate. You can also paste them into a Workspace window and execute them there. Finally, you may also find those snippets via the Method Finder, when entering the desired result value.

Bits & Bytes[Bearbeiten]

Set, Clear or Toggle a Bit[Bearbeiten]

Smalltalk:

|numIn result|

numIn := 0b10011001.
"/ using masks
result := numIn bitOr: 0b00110000.    "/ to set the two bits
result := numIn bitAnd: 0b11110000.   "/ to mask bits
result := numIn bitClear: 0b00000011. "/ to clear bits
result := numIn bitXor: 0b00001100.   "/ to toggle bits
result := numIn bitTest: 0b00001100.  "/ to test if masked bits are all set

"/ using bit numbers (index starts with 1 for the least significant bit)
result := numIn bitAt: 1.             "/ to extract the first bit 
result := numIn setBit: 2.            "/ set the second bit
result := numIn clearBit: 2.          "/ clear the second bit
result := numIn invertBit: 2.         "/ toggle the second bit
 

JavaScript:

var numIn, result;

numIn = 0b10011001;
// using masks
result = numIn | 0b00110000;         // to set the two bits
result = numIn & 0b11110000;         // to mask bits
result = numIn & ˜0b00000011;        // to clear bits
result = numIn ^ 0b00001100;         // to toggle bits
result = (numIn & 0b00001100) != 0;  // to test if masked bits are all set

// using bit numbers (index starts with 1 for the least significant bit)
result = numIn.bitAt(1);             // to extract the first bit 
result = numIn.setBit(2);            // set the second bit
result = numIn.clearBit(2);          // clear the second bit
result = numIn.invertBit(2);         // toggle the second bit

Extracting Bytes[Bearbeiten]

Byte Order[Bearbeiten]

Numeric[Bearbeiten]

String/Text Processing[Bearbeiten]

Searching/Extracting Parts from a Document[Bearbeiten]

File I/O[Bearbeiten]

Sockets[Bearbeiten]

HTML[Bearbeiten]

XML[Bearbeiten]

JSON[Bearbeiten]



Copyright © 2014-2024 eXept Software AG