"Sputnik" help  
Sputnik Help
Language Reference - Datatypes - Strings (Bitwise Operators)

Strings (Bitwise Operators)

See "Strings (As Numbers)" before reading this section.

Bitstrings of any size may be manipulated by the bitwise operators like ~ | & ^ etc.

If the operands to a binary bitwise op are strings of different sizes, ops act as though the shorter operand had additional zero bits on the right. The granularity for such extension is one or more bytes.

Since Sputnik strings are Unicode (UTF8) when you do an operation like this it makes sure to properly cast as byte to over going over into.

// ASCII-based examples from Perl (applies to Sputnik)
print "j p \n" ^ " a h";            // prints "JAPH\n"
print "JA" | "  ph\n";              // prints "japh\n"
print "japh\n" & "_____";           // prints "JAPH\n";
print @"p N$" ^ " E<H\n";           // prints "Perl\n";

If you are intending to manipulate bitstrings, be certain that you're supplying bitstrings: If an operand is a number, that will imply a numeric bitwise operation. You may explicitly show which type of operation you intend by using "" or 0+ , as in the examples below.

$foo = 150 | 105;                   // yields 255 (0x96 | 0x69 is 0xFF)
$foo = "150" | 105;                 // yields 255
$foo = 150 | "105";                 // yields 255
$foo = "150" | "105";               // yields string '155' (under ASCII)
$baz = 0+$foo & 0+$bar;             // both ops explicitly numeric
$biz = "$foo" ^ "$bar";             // both ops explicitly stringy
$biz = (string)$foo ^ (string)$bar; // both ops explicitly stringy
                                    // (of course you can use any cast)

 


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org