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.

7742 questions
116
votes
3 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
  • 17,084
  • 9
  • 43
  • 67
115
votes
9 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
  • 6,622
  • 20
  • 58
  • 78
110
votes
12 answers

How to Convert Int to Unsigned Byte and Back

I need to convert a number into an unsigned byte. The number is always less than or equal to 255, and so it will fit in one byte. I also need to convert that byte back into that number. How would I do that in Java? I've tried several ways and none…
darksky
  • 20,411
  • 61
  • 165
  • 254
106
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,219
  • 2
  • 10
  • 16
100
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
  • 9,843
  • 13
  • 42
  • 73
98
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
  • 129,499
  • 52
  • 291
  • 397
96
votes
4 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
  • 8,402
  • 14
  • 47
  • 73
93
votes
9 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
  • 9,355
  • 7
  • 28
  • 33
92
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
  • 925
  • 1
  • 6
  • 6
89
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
  • 25,853
  • 63
  • 179
  • 294
87
votes
11 answers

In Go, how can I convert a struct to a byte array?

I have an instance of a struct that I defined and I would like to convert it to an array of bytes. I tried []byte(my_struct), but that did not work. Also, I was pointed to the binary package, but I am not sure which function I should use and how I…
abw333
  • 5,571
  • 12
  • 41
  • 48
87
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,943
  • 14
  • 43
  • 60
86
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
  • 7,188
  • 17
  • 64
  • 103
86
votes
4 answers

How to store a byte array in Javascript

I'm going to be storing a large array of byte values (most likely over a million) in Javascript. If I use a normal array with normal numbers, that will take 8 MB, because numbers are stored as IEEE doubles, but if I can store it as bytes, it will be…
Kendall Frey
  • 43,130
  • 20
  • 110
  • 148
85
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,990
  • 5
  • 33
  • 37