The difference between logical shift right, arithmetic shift right, and rotate right

First remember that machine words are of fixed size. Say 4, and that your input is: +—+—+—+—+ | a | b | c | d | +—+—+—+—+ Then pushing everything one position to the left gives: +—+—+—+—+ | b | c | d | X | +—+—+—+—+ Question what to put as X? with a … Read more

How can I cast an int to a bit in MySQL 5.1?

You cannot! CAST and CONVERT only work to: BINARY[(N)] CHAR[(N)] DATE DATETIME DECIMAL[(M[,D])] SIGNED [INTEGER] TIME UNSIGNED [INTEGER] No room for: BIT, BITINT, TINYINT, MEDIUMINT, BIGINT, SMALLINT, … However, you can create your own function cast_to_bit(n): DELIMITER $$ CREATE FUNCTION cast_to_bit (N INT) RETURNS bit(1) BEGIN RETURN N; END To try it yourself, you can … Read more

C/C++ efficient bit array

Since you mention C as well as C++, I’ll assume that a C++-oriented solution like boost::dynamic_bitset might not be applicable, and talk about a low-level C implementation instead. Note that if something like boost::dynamic_bitset works for you, or there’s a pre-existing C library you can find, then using them can be better than rolling your … Read more

What does “real*8” mean?

The 8 refers to the number of bytes that the data type uses. So a 32-bit integer is integer*4 along the same lines. A quick search found this guide to Fortran data types, which includes: The “real*4” statement specifies the variable names to be single precision 4-byte real numbers which has 7 digits of accuracy … Read more

how to print memory bits in c

You would need to assign a pointer to the variable in question to a char *, and treat it as an array of bytes of length sizeof(variable). Then you can print each byte in hex using the %X format specifier to printf. You can define a function like this: void print_bytes(void *ptr, int size) { … Read more

tech