Questions tagged [byte]

A unit of information usually corresponding to 8 bits. This term is also most often used to indicate the smallest addressable unit of storage on a digital system.

A unit of information usually corresponding to 8 bits. This term is also most often used to indicate the smallest addressable unit of storage on a digital system.

These days, the term byte usually refers to a unit of information consisting of 8 . Historically, other sizes have been used as well. If one wants to stress the fixed size, the term octet can be used instead.

7028 questions
94
votes
6 answers

Hashing with SHA1 Algorithm in C#

I want to hash given byte[] array with using SHA1 Algorithm with the use of SHA1Managed. The byte[] hash will come from unit test. Expected hash is 0d71ee4472658cd5874c5578410a9d8611fc9aef (case sensitive). How can I achieve this? public string…
Merve Kaya
  • 1,089
  • 1
  • 9
  • 16
91
votes
5 answers

Write bytes to file

I have a hexadecimal string (e.g 0CFE9E69271557822FE715A8B3E564BE) and I want to write it to a file as bytes. For example, Offset 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 00000000 0C FE 9E 69 27 15 57 82 2F E7 15 A8 B3 E5 64 BE …
John Doe
  • 8,295
  • 12
  • 38
  • 55
90
votes
9 answers

System where 1 byte != 8 bit?

All the time I read sentences like don't rely on 1 byte being 8 bit in size use CHAR_BIT instead of 8 as a constant to convert between bits and bytes et cetera. What real life systems are there today, where this holds true? (I'm not sure if there…
Xeo
  • 123,374
  • 44
  • 277
  • 381
84
votes
7 answers

How to convert byte[] to Byte[] and the other way around?

How to convert byte[] to Byte[] and also Byte[] to byte[], in the case of not using any 3rd party library? Is there a way to do it fast just using the standard library?
user926958
  • 8,801
  • 7
  • 24
  • 32
83
votes
2 answers

Writing then reading in-memory bytes (BytesIO) gives a blank result

I wanted to try out the python BytesIO class. As an experiment I tried writing to a zip file in memory, and then reading the bytes back out of that zip file. So instead of passing in a file-object to gzip, I pass in a BytesIO object. Here is the…
twasbrillig
  • 12,313
  • 7
  • 37
  • 61
82
votes
4 answers

Byte Array in Python

How can I represent a byte array (like in Java with byte[]) in Python? I'll need to send it over the wire with gevent. byte key[] = {0x13, 0x00, 0x00, 0x00, 0x08, 0x00};
d0ctor
  • 825
  • 1
  • 6
  • 6
80
votes
4 answers

How to convert between bytes and strings in Python 3?

This is a Python 101 type question, but it had me baffled for a while when I tried to use a package that seemed to convert my string input into bytes. As you will see below I found the answer for myself, but I felt it was worth recording here…
Bobble
  • 2,721
  • 3
  • 20
  • 29
79
votes
3 answers

What is the maximum number of bytes for a UTF-8 encoded character?

What is the maximum number of bytes for a single UTF-8 encoded character? I'll be encrypting the bytes of a String encoded in UTF-8 and therefore need to be able to work out the maximum number of bytes for a UTF-8 encoded String. Could someone…
Edd
  • 7,660
  • 14
  • 44
  • 70
79
votes
4 answers

Java - Convert int to Byte Array of 4 Bytes?

Possible Duplicate: Convert integer into byte array (Java) I need to store the length of a buffer, in a byte array 4 bytes large. Pseudo code: private byte[] convertLengthToByte(byte[] myBuffer) { int length = myBuffer.length; byte[]…
Petey B
  • 10,781
  • 22
  • 73
  • 101
79
votes
8 answers

Why is the range of bytes -128 to 127 in Java?

I don't understand why the lowest value a byte can take is -128. I can see that the highest value is 127, because it's 01111111 in binary, but how does one represent -128 with only 8 bits, one of which is used for the sign? Positive 128 would…
Bad Request
  • 3,810
  • 5
  • 29
  • 35
79
votes
6 answers

How to convert from []byte to int in Go Programming

I need to create a client-server example over TCP. In the client side I read 2 numbers and I send them to the server. The problem I faced is that I can't convert from []byte to int, because the communication accept only data of type []byte. Is there…
Emanuel
  • 5,832
  • 17
  • 55
  • 74
78
votes
5 answers

Set specific bit in byte

I'm trying to set bits in Java byte variable. It does provide propper methods like .setBit(i). Does anybody know how I can realize this? I can iterate bit-wise through a given byte: if( (my_byte & (1 << i)) == 0 ){ } However I cannot set this…
wishi
  • 6,348
  • 14
  • 55
  • 92
75
votes
3 answers

When to use byte array & when byte buffer?

What is the difference between a byte array & byte buffer ? Also, in what situations should one be preferred over the other? [my usecase is for a web application being developed in java].
Rajat Gupta
  • 23,343
  • 56
  • 165
  • 281
74
votes
7 answers

Saving any file to in the database, just convert it to a byte array?

Is converting a file to a byte array the best way to save ANY file format to disk or database var binary column? So if someone wants to save a .gif or .doc/.docx or .pdf file, can I just convert it to a bytearray UFT8 and save it to the db as a…
Blankman
  • 236,778
  • 296
  • 715
  • 1,125
72
votes
4 answers

C program to check little vs. big endian

Possible Duplicate: C Macro definition to determine big endian or little endian machine? int main() { int x = 1; char *y = (char*)&x; printf("%c\n",*y+48); } If it's little endian it will print 1. If it's big endian it will print 0. Is…
ordinary
  • 5,155
  • 10
  • 40
  • 58