Expecco Code Snippets/en: Unterschied zwischen den Versionen

Aus expecco Wiki (Version 25.x)
Zur Navigation springen Zur Suche springen
Inhalt gelöscht Inhalt hinzugefügt
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.
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 [[How_to_Program/en#Find_Functions_by_Example | Method Finder]], when entering the desired result value.


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

Version vom 18. September 2020, 13:20 Uhr

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

Set, Clear or Toggle a Bit

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

Byte Order

Numeric

String/Text Processing

Searching/Extracting Parts from a Document

File I/O

Sockets

HTML

XML

JSON



Copyright © 2014-2024 eXept Software AG