bit

How to add and subtract 16 bit floating point half precision numbers?

爱⌒轻易说出口 提交于 2019-12-24 03:15:10
问题 How do I add and subtract 16 bit floating point half precision numbers? Say I need to add or subtract: 1 10000 0000000000 1 01111 1111100000 2’s complement form. 回答1: Assuming you are using a denormalized representation similar to that of IEEE single/double precision, just compute the sign = (-1)^S, the mantissa as 1.M if E != 0 and 0.M if E == 0, and the exponent = E - 2^(n-1), operate on these natural representations, and convert back to the 16-bit format. sign1 = -1 mantissa1 = 1.0

How to check Architecture of android device and show them?

痞子三分冷 提交于 2019-12-24 02:58:12
问题 I am working on a app which works on the Architecture of devices, means if user is using 32bit phone, it will show some different function andfor 64bit some other function. If there is a way that can also print their bit on device and let user know. Thank in advance 回答1: My answer borrows from both Patel and Majumder. If you want to do something with a specific architecture, then you should check for which specific instruction set you want to work under(if you want to find out more than if it

订单Id生成之雪花算法

二次信任 提交于 2019-12-24 01:09:22
不跟你多BB,上张图好说话 为什么 是64位呢,因为返回值是long类型是64位,但是第一位是符号位不可用,所有只剩下63位 时间戳的长度,决定了该算法使用的年限,时间戳记录的不是当前时间戳,而是当前时间戳和和起始时间戳的差值,起始时间戳由程序员自己设置 41位 按如下公式计算可用时间约为 (1L << 41) / (1000L * 60 * 60 * 24 * 365) = 49 年 ,可根据实际情况控制 工作机器id 的长度 序列号位数决定了当前毫秒,当前机器能产生的最多订单号 2^12 = 4096 个 工作机器id 的长度决定了能支持同时多少台机器使用 2^10 = 1024 /** * @author wcn * @date 2019/12/23 17:09 */ public class SnowFlakeUtil { /** * 起始的时间戳 */ private final static long START_STMP = 1480166465631 L ; /** * 序列号占用的位数 每一部分占用的位数,就三个 最大值为:2^12 = 4095 */ private final static long SEQUENCE_BIT = 12 ; /** * 机器标识占用的位数 最大值为:2^5 = 31 */ private final static long

Read and write file bit by bit

百般思念 提交于 2019-12-24 00:58:39
问题 There is a .jpg file for example or some other file. I want to read it bit by bit. I do this: open(FH, "<", "red.jpg") or die "Error: $!\n"; my $str; while(<FH>) { $str .= unpack('B*', $_); } close FH; Well it gives me $str with 0101001 of the file. After that I do this: open(AB, ">", "new.jpg") or die "Error: $!\n"; binmode(AB); print AB $str; close AB; but it doesn't work. How can I do it? and how to do that that it would work regardless of byte order(cross-platform)? 回答1: Problems: You're

Moving a bit within a byte using bitfield or bitwise operators

╄→гoц情女王★ 提交于 2019-12-23 09:50:55
问题 Is there an elegant way of moving a bit within a byte (or word/long). For simplicity, lets use a simple 8-bit byte and just one bit to move within the byte. Given a bit number, based on 0-7 Least-sig-bit to most-sig-bit, (or bits 1-8 if you'd rather), I would like to move a bit from one position to another: 7654 3210 <bit position 0101 1010 <some binary value --x- --y- <move bit from x to y 0111 0100 <new value with x moved to y and intervening bits shifted left So, x at bit position 5 moves

Bit shifting a character with wrap? C++

倖福魔咒の 提交于 2019-12-23 09:12:59
问题 I have a binary file that will be read in as characters. Each character was bit shifted to the left unknown number of times (assuming with wrap) by someone else. I want to be able to read in each character and then wrap shift to the right (the number of times to shift I guess will have to be figured out manually, because I haven't figured out another way). So, my current idea is that I read in a character, create a copy with temp and then use XOR: char letter; //will hold the read in letter

Create 1 bit bitmap (monochrome) in php

丶灬走出姿态 提交于 2019-12-23 08:48:06
问题 I'm looking for the possibility of write a 1 bit bitmap from a string with this content: $str = "001011000111110000"; Zero is white and One is black. The BMP file will be 18 x 1 px. I don't want a 24bit BMP, but a real 1bit BMP. Does anyone know the header and the conversion method in PHP? 回答1: That's a little bit of a strange request :) So, what you'd want to use here is php-gd, for a start. Generally this is included when installing php on any OS with decent repo's, but just incase it isn't

Represent 10000 booleans using only 10000 bits

試著忘記壹切 提交于 2019-12-23 06:27:06
问题 I want to represent 10000 bits of information.(Each can be either one or zero). Is there any way I can do this? Wikipedia explains a bit hack to achieve this. But then it asks me to have a number that's as large as 2^10000 for storing 10000 bits. Is there some way that's tractable even for storing large number of bits? 回答1: As wikipedia explains, a bit field is an appropriate choice here. a bit field that can hold 10,000 bits has 2^10000 states. A good choice for doing this (given that

Perl: seek to and read bits, not bytes

青春壹個敷衍的年華 提交于 2019-12-23 06:10:18
问题 In Perl, I want to seek to the nth bit (not byte) of a file and then read the next m bits, returned as a list of 0s and 1s. Is there any easy way to do this? I realize I can write a subroutine wrapping regular seek and read, but was wondering if there's a easier solution. 回答1: If n is a multiple of m, and m is one of 1, 2, 4, 8, 16, 32, and on some platforms, 64, you can read the whole file into a string and use vec for this. (Admittedly a fairly constraining case, but a common one.) Barring

sign extension in C

偶尔善良 提交于 2019-12-22 14:07:17
问题 I'm looking here to understand sign extension: http://www.shrubbery.net/solaris9ab/SUNWdev/SOL64TRANS/p8.html struct foo { unsigned int base:19, rehash:13; }; main(int argc, char *argv[]) { struct foo a; unsigned long addr; a.base = 0x40000; addr = a.base << 13; /* Sign extension here! */ printf("addr 0x%lx\n", addr); addr = (unsigned int)(a.base << 13); /* No sign extension here! */ printf("addr 0x%lx\n", addr); } They claim this: ------------------ 64 bit: % cc -o test64 -xarch=v9 test.c %