bit-manipulation

How to correctly convert from rgb565 to rgb888

断了今生、忘了曾经 提交于 2019-12-13 04:27:39
问题 I'm trying to convert a value from rgb565 to rgb888 but I can't seem to get it right. I've also checked a few existing answers like this one but there are values that don't seem to be properly convert. Here's what I've tried so far: PImage picker; int c; void setup(){ size(285,240); picker = loadImage("hsv.gif"); int c = color(255,255,255); byte[] word = colorToWord(c); int[] rgb = wordToRGB(word); noStroke(); fill(c); rect(0,0,50,100); fill(rgb[0],rgb[1],rgb[2]); rect(50,0,50,100); } void

How To Convert a 32-bit Integer into a 64 bit value In C

喜你入骨 提交于 2019-12-13 04:07:24
问题 I am getting compilation error in a Project Code where the situation is as follows: typedef unsigned int U32bit; typedef unsigned long long U64bit; U32bit var; U64bit var2; var = function(); /* Function returns a 32-bit value, which is stored in var */ var2 = 100*var1; /* 100*var1 is very Big & can be stored only in U64bit variable */ For the Above Line: var2 = 100*var1 I am getting the following Compilation Error on Solaris: "conversion to non-scalar type requested" I have also tried

10's complement of a number statement

无人久伴 提交于 2019-12-13 03:34:05
问题 The values of a,x,y if 47x80 is the 10's complement of yaya0 is: I calculated the 10's complement of yaya0 to be 100,000-yaya0 and then. 47x80=100,000-yaya0 Now how to find values ? 回答1: 47080 + 100x = 100000 - (10000y + 1000a + 100y + 10a) 52920 = 100x + 10100y + 1010a ==> a = 2 otherwise you won`t get the 2 as tens 50900 = 100x + 10100y this can be split up in 5 = y and 9 = x + y so a = 2 x = 4 y = 5 回答2: 47x80 represents a number where 'x' is the hundreds. So does yaya0 where 'y' represent

VB.NET Bit manipulation: how to extract byte from short?

孤街醉人 提交于 2019-12-13 02:14:50
问题 Given this Short (signed): &Hxxxx I want to: Extract the most right &HxxFF as SByte (signed) Extract the left &H7Fxx as Byte (unsigned) Identify if the most left &H8xxx is positive or negative (bool result) 回答1: Uh... value & 0x00ff (value & 0xff00) >> 8 (value & 0xf000) >= 0 EDIT: I suppose you want the byte value and not just the upper 8 bits. 回答2: Extract the most right 0xxxff myShort & 0x00FF Extract the left 0xffxx (myShort & 0xFF00) >> 8 Identify if the most left 0xfxxx is positive or

IEEE 754 to decimal in C language

房东的猫 提交于 2019-12-13 02:14:00
问题 I'm looking the best way to transform a float number to its decimal representation in C. I'll try to give you an example: the user introduces a number in IEEE754 (1 1111111 10101...) and the program has to return the decimal representation (ex. 25.6) I've tried with masks, and bitwise operations, but I haven't got any logical result. 回答1: I believe the following is performing the operation you describe: I use the int as an intermediate representation because it has the same number of bits as

Confusing PHP bitwise NOT behavior

前提是你 提交于 2019-12-13 01:59:05
问题 In PHP, if I run the following simple program $number = 9; var_dump( ~ $number ); my output is int(-10) This is confusing to me. I thought ~ was the bitwise NOT operator. So I was expecting something like. if binary 9 is 00000000000000000000000000001001 then Bitwise NOT 9 11111111111111111111111111110110 Meaning ~9 should come out as some ludicrously large integer like 4,294,967,286 . What subtly of precedence, type coercion, or something else am I missing here? 回答1: Your output is defaulting

Bitwise Shift - Getting different results in C#.net vs PHP

北城以北 提交于 2019-12-13 01:44:55
问题 When I run this command in PHP, I get: Code: 2269495617392648 >> 24 Result: 32 When I run it in C#.net or vb.net, I get: Code: 2269495617392648 >> 24 Result: 135272480 PHP is correct. The interesting thing is, that when I try to shift any number greater than int32 in .net, it yields bad results.. Every number under int32 (2147483647) yields the same results from php and c#.net or vb.net Is there a workaround for this in .net? 回答1: Strictly speaking, PHP is wrong. The entire bit pattern of the

How to simulate the MySQL bit_count function in Sybase SQL Anywhere?

我只是一个虾纸丫 提交于 2019-12-13 01:25:50
问题 MySQL's bit_count function is quite useful for some cases: http://dev.mysql.com/doc/refman/5.5/en/bit-functions.html#function_bit-count Now I would like to use that function in other databases, that do not support it. What's the simplest way to do it (without creating a stored function, as I do not have access to the client database on a DDL level). One pretty verbose option is this (for TINYINT data types): SELECT (my_field & 1) + (my_field & 2) >> 1 + (my_field & 4) >> 2 + (my_field & 8) >>

How does 1 left shift by 31 (1 << 31) work to get maximum int value? Here are my thoughts and some explanations I found online

大憨熊 提交于 2019-12-12 22:53:11
问题 I'm fairly new to bit manipulation and I'm trying to figure out how (1 << 31) - 1 works. First I know that 1 << 31 is 1000000000000000000000000000 and I know it's actually complement of minimum int value, but when I tried to figure out (1 << 31) - 1, I found an explanation states that, it's just 10000000000000000000000000000000 - 1 = 01111111111111111111111111111111 I was almost tempted to believe it since it's really straightforward. But is this what really happening? If it's not, why it

3 ways to toggle a bit represented as a char

人盡茶涼 提交于 2019-12-12 22:31:58
问题 I wrote this: #include <iostream> #include <vector> int main() { std::vector<char> v = {0, 0, 0}; v[0] = v[0] == 0 ? 1 : 0; v[1] = !v[1]; v[2] ^= 1; std::cout << (int)v[0] << (int)v[1] << (int)v[2] << "\n"; return 0; } which toggles all bits, but I actually care on changing only the i-th bit. What am I interested in is which one of these ways should one use in a c++ project, when the only thing that you care is speed (not memory and readability)? The reason for using std::vector<char> as a