byte-shifting

convert 24bit RGB to ARGB16

和自甴很熟 提交于 2019-12-25 00:37:59
问题 I have to read a 24bpp Bitmap and convert each pixel from RGB24 to ARGB16 . I used the following code, #define ARGB16(a, r, g, b) ( ((a) << 15) | (r)|((g)<<5)|((b)<<10)) But I am not getting the required Output. Any help would be highly appreciated. 回答1: Break it up. Let's continue to use macros: #define TRUNCATE(x) ((x) >> 3) #define ARGB16(a,r,g,b) ((a << 15) | (TRUNCATE(r) << 10) | (TRUNCATE(g) << 5) | TRUNCATE(b))) This assumes the alpha is just a single bit. 回答2: Since the RGB values are

How to convert a string to a byte array which is compiled with a given charset in Go?

佐手、 提交于 2019-12-12 16:37:57
问题 In java, we can use the method of String : byte[] getBytes(Charset charset) . This method Encodes a String into a sequence of bytes using the given charset, storing the result into a new byte array. But how to do this in GO? Is there any similar way in Go can do this? Please let me know it. 回答1: The standard Go library only supports Unicode (UTF-8, UTF-16, UTF-32) and ASCII encoding. ASCII is a subset of UTF-8. The go-charset package (found from here) supports conversion to and from UTF-8 and

Why left shifting in java changing the sign value

一笑奈何 提交于 2019-12-10 22:09:04
问题 I am working on java. I am wondering why java producing this output. I am sharing the code here. public class vvn { public static void main(String[] args) { byte [] arr = new byte[4]; arr[0] = (byte)157; arr[1] = 1; arr[2] = 0; arr[3] = 0; System.out.format("read 0x%x 0x%x 0x%x 0x%x \n",arr[3],arr[2],arr[1],arr[0]); int v = (arr[0] | (arr[1] << 8) | (arr[2] << 16) | (arr[3] << 24)); System.out.format("read 0x%x\n",v); } } And I got the output as read 0x0 0x0 0x1 0x9d read 0xffffff9d I