Tutorial by Examples: bits

The operators << and >> are commonly used as "write" and "read" operators: std::ostream overloads << to write variables to the underlying stream (example: std::cout) std::istream overloads >> to read from the underlying stream to a variable (example: s...
A binary is a sequence of unsigned 8-bit bytes. 1> <<1,2,3,255>>. <<1,2,3,255>> 2> <<256,257,258>>. <<0,1,2>> 3> <<"hello","world">>. <<"helloworld">> A bitstring is a generalized ...
Assuming we want to modify bit n of an integer primitive, i (byte, short, char, int, or long): (i & 1 << n) != 0 // checks bit 'n' i |= 1 << n; // sets bit 'n' to 1 i &= ~(1 << n); // sets bit 'n' to 0 i ^= 1 << n; // toggles the value of bit 'n' Us...
C-style bit-manipulation x = -1; // -1 == 1111 1111 ... 1111b (See here for an explanation of why this works and is actually the best approach.) Using std::bitset std::bitset<10> x; x.set(); // Sets all bits to '1'
This is the default calling convention for 64-bit applications on many POSIX operating systems. Parameters The first eight scalar parameters are passed in (in order) RDI, RSI, RDX, RCX, R8, R9, R10, R11. Parameters past the first eight are placed on the stack, with earlier parameters closer to th...
stdcall is used for 32-bit Windows API calls. Parameters Parameters are passed on the stack, with the first parameter closest to the top of the stack. The callee will pop these values off of the stack before returning. Return Value Scalar return values are placed in EAX. Saved and Clobbered Re...
In C++, a byte is the space occupied by a char object. The number of bits in a byte is given by CHAR_BIT, which is defined in climits and required to be at least 8. While most modern systems have 8-bit bytes, and POSIX requires CHAR_BIT to be exactly 8, there are some systems where CHAR_BIT is great...
If the shift count value is a negative value then both left shift and right shift operations are undefined1: int x = 5 << -3; /* undefined */ int x = 5 >> -3; /* undefined */ If left shift is performed on a negative value, it's undefined: int x = -5 << 3; /* undefined */ I...
Binaries in elixir are created using the Kernel.SpecialForms construct <<>>. They are a powerful tool which makes Elixir very useful for working with binary protocols and encodings. Binaries and bitstrings are specified using a comma delimited list of integers or variable values, booke...
The population count of a bitstring is often needed in cryptography and other applications and the problem has been widely studied. The naive way requires one iteration per bit: unsigned value = 1234; unsigned bits = 0; // accumulates the total number of bits set in `n` for (bits = 0; value; ...
On 32-bit systems, integers greater than 0x7FFFFFFF cannot be stored primitively, while integers between 0x0000000080000000 and 0x7FFFFFFFFFFFFFFF can be stored primitively on 64-bit systems but not 32-bit systems (signed long long). However, since 64-bit systems and many other languages support sto...
Since 1.7 there's a java.util.BitSet class that provides simple and user-friendly bit storage and manipulation interface: final BitSet bitSet = new BitSet(8); // by default all bits are unset IntStream.range(0, 8).filter(i -> i % 2 == 0).forEach(bitSet::set); // {0, 2, 4, 6} bitSet.set(3);...
Clarification of Erlang doc on Bit Syntax: 4.4 Defaults [Beginning omitted: <<3.14>> isn't even legal syntax.] The default Size depends on the type. For integer it is 8. For float it is 64. For binary it is the actual size of the specified binary: 1> Bin = << 17/integ...
BITSADMIN was used to transfer documents, download website, download files from websites, etc... This command is a deprecated command, and may be removed on next Windows updates. To prevent this issue, use the new Powershell BIT cmdlet. Here is a sample code utilizing BITSADMIN. @echo off Bitsa...
Like list, simplest function over iolist and bitstring is: -spec loop(iolist()) -> ok | {ok, iolist} . loop(<<>>) -> ok; loop(<<Head, Tail/bitstring>>) -> loop(Tail); loop(<<Rest/bitstring>>) -> {ok, Rest} You can call it like this: lo...

Page 1 of 1