Binary strings: Difference between revisions
Replace println() with print(); replace output "syntaxhighlight" tag with "pre" tag
(Add Ecstasy example) |
(Replace println() with print(); replace output "syntaxhighlight" tag with "pre" tag) |
||
Line 1,122:
Byte[] fixedLength = new Byte[10]; // fixed length string of bytes (all default to 0)
Byte[] literal = [0, 1, 7, 0xff]; // a "constant" string of bytes
console.
console.
mutableBytes += 0; // add a byte (using an operator)
mutableBytes.add(1); // add a byte (using the underlying method)
mutableBytes.addAll(#07FF); // add multiple bytes (using the underlying method)
console.
console.
fixedLength = new Byte[4](i -> literal[i]); // create/copy from literal to fixedLength
val clone = fixedLength.clone(); // clone the array
console.
console.
for (Int start = 0; Int index := fixedLength.indexOf(0x01, start); start = index)
Line 1,169:
fixedLength[index] = 0x04;
}
console.
for (Int start = 0; Int index := mutableBytes.indexOf(#0107, start); start = index)
Line 1,178:
mutableBytes.replaceAll(index, #9876);
}
console.
console.
}
}
</syntaxhighlight>
{{out}}
<pre>
String creation and assignment:
mutableBytes=0x
Line 1,227:
Join strings:
mutableBytes+fixedLength+literal=0x009876FF000407FF000107FF
</pre>
=={{header|Elixir}}==
|