byte

Read binary data (from file) into a struct

為{幸葍}努か 提交于 2019-12-20 10:37:27
问题 I'm reading binary data from a file, specifically from a zip file. (To know more about the zip format structure see http://en.wikipedia.org/wiki/ZIP_%28file_format%29) I've created a struct that stores the data: typedef struct { /*Start Size Description */ int signatute; /* 0 4 Local file header signature = 0x04034b50 */ short int version; /*  4 2 Version needed to extract (minimum) */ short int bit_flag; /*  6 2 General purpose bit flag */ short int compression_method; /*  8 2 Compression

How to read a file byte by byte in Python and how to print a bytelist as a binary?

喜你入骨 提交于 2019-12-20 09:35:57
问题 I'm trying to read a file byte by byte, but I'm not sure how to do that. I'm trying to do it like that: file = open(filename, 'rb') while 1: byte = file.read(8) # Do something... So does that make the variable byte to contain 8 next bits at the beginning of every loop? It doesn't matter what those bytes really are. The only thing that matters is that I need to read a file in 8-bit stacks. EDIT: Also I collect those bytes in a list and I would like to print them so that they don't print out as

How to read a file byte by byte in Python and how to print a bytelist as a binary?

非 Y 不嫁゛ 提交于 2019-12-20 09:31:20
问题 I'm trying to read a file byte by byte, but I'm not sure how to do that. I'm trying to do it like that: file = open(filename, 'rb') while 1: byte = file.read(8) # Do something... So does that make the variable byte to contain 8 next bits at the beginning of every loop? It doesn't matter what those bytes really are. The only thing that matters is that I need to read a file in 8-bit stacks. EDIT: Also I collect those bytes in a list and I would like to print them so that they don't print out as

How to download Postgres bytea column as file

你离开我真会死。 提交于 2019-12-20 08:57:34
问题 Currently, i have a number of files stored in postgres 8.4 as bytea. The file types are .doc, .odt, .pdf, .txt and etc. May i know how to download all the file stored in Postgres because i need to to do a backup. I need them in their original file type instead of bytea format. Thanks! 回答1: One simple option is to use COPY command with encode to hex format and then apply xxd shell command (with -p continuous hexdump style switch). For example let's say I have jpg image in bytea column in

BigInteger -> byte[] -> Biginteger. Looks equal but if statement fails

别等时光非礼了梦想. 提交于 2019-12-20 07:49:04
问题 I am playing around with an idea I have for storing a public key for myself. For this I would need to transform the BigInteger in some sort of a variable and then recreate the BigInteger from that value. I have searched through Stackoverflow to find the best way to do this is with byte[]. This is my code in Eclipse: import java.math.BigInteger; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.interfaces.RSAPublicKey; public class Vaja2 { public static

Converting 8 bytes to double [duplicate]

大兔子大兔子 提交于 2019-12-20 06:48:26
问题 This question already has answers here : How to convert a byte array into double in C? (3 answers) Closed 5 years ago . I am facing some problem with converting 8 bytes to a double. I have following byte array 0x98 0xf9 0x38 0x4e 0x3a 0x9f 0x1c 0x43 And I am trying to do following for (int i = 1; i < 8; i++) mult[i] = 256 * mult[i - 1]; double out= buf[7] * mult[7] + buf[6] * mult[6] + buf[5] * mult[5] + buf[4] * mult[4] + buf[3] * mult[3] + buf[2] * mult[2] + buf[1] * mult[1] + buf[0] * mult

C# - Shifting and reversing the order of bits in a byte array

南笙酒味 提交于 2019-12-20 05:57:45
问题 I am trying to get the correct int out of an array of bytes. The bytes is read from a RFIDTag via POS for .Net. (Acctually I need 18 bits) In binary the byte array is as follows: 00001110 11011100 00000000 00011011 10000000 What I need to get out of it is: 00 00000000 11101101 (int = 237) From the original bytes that would be the following bits in reverse order: ------10 11011100 00000000 I have been looking at bitArray. Array.Reverse. And several ways of shifting bits. But I just can't wrap

Byte typecasting in java

喜欢而已 提交于 2019-12-20 05:48:21
问题 the program gives me loss of precision error but i cant think of any precision loss since numbers are small This is the code ## class Demo { public static void main(String args[]) { byte b1=3; byte b2=2; byte b3=b1+b2; System.out.println(b3); } } 回答1: The addition expression b1 + b2 is of type int - there aren't any addition operators defined on smaller types than int . So in order to convert that back to a byte , you have to cast: byte b3 = (byte) (b1 + b2); Note that although you happen to

Byte typecasting in java

◇◆丶佛笑我妖孽 提交于 2019-12-20 05:48:11
问题 the program gives me loss of precision error but i cant think of any precision loss since numbers are small This is the code ## class Demo { public static void main(String args[]) { byte b1=3; byte b2=2; byte b3=b1+b2; System.out.println(b3); } } 回答1: The addition expression b1 + b2 is of type int - there aren't any addition operators defined on smaller types than int . So in order to convert that back to a byte , you have to cast: byte b3 = (byte) (b1 + b2); Note that although you happen to

Store 4 different values in a byte

China☆狼群 提交于 2019-12-20 05:24:26
问题 I have an assignment to do, but I have no clue where to start. I am not expecting and definitely do not want answers in code. I would like some guidance as in what to do because I feel a bit lost. Pack and unpack variables into a byte . You need to store 4 different values in a byte. The values are: NAME RANGE BITS engine_on 0-1 1 gear_pos 0-4 3 key_pos 0-2 2 brake1 0-1 1 brake2 0-1 1 (LSB, Least significant bit ) Write a program bytess.c that takes 5 arguments (less or more should be treated