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
160
votes
8 answers

Convert bytes to int?

I'm currently working on an encryption/decryption program and I need to be able to convert bytes to an integer. I know that: bytes([3]) = b'\x03' Yet I cannot find out how to do the inverse. What am I doing terribly wrong?
Vladimir Shevyakov
  • 2,511
  • 4
  • 19
  • 40
158
votes
13 answers

Convert any object to a byte[]

I am writing a prototype TCP connection and I am having some trouble homogenizing the data to be sent. At the moment, I am sending nothing but strings, but in the future we want to be able to send any object. The code is quite simple at the moment,…
Steve H.
  • 3,283
  • 4
  • 24
  • 32
154
votes
10 answers

How to Get True Size of MySQL Database?

I would like to know how much space does my MySQL database use, in order to select a web host. I found the command SHOW TABLE STATUS LIKE 'table_name' so when I do the query, I get something like this: Name | Rows | Avg. Row Length |…
marvin
  • 1,847
  • 4
  • 15
  • 20
153
votes
4 answers

How to know the size of the string in bytes?

I'm wondering if I can know how long in bytes for a string in C#, anyone know?
user705414
  • 20,472
  • 39
  • 112
  • 155
148
votes
11 answers

Convert integer into byte array (Java)

what's a fast way to convert an Integer into a Byte Array? e.g. 0xAABBCCDD => {AA, BB, CC, DD}
Buttercup
  • 2,007
  • 2
  • 15
  • 9
143
votes
14 answers

How many bytes in a JavaScript string?

I have a javascript string which is about 500K when being sent from the server in UTF-8. How can I tell its size in JavaScript? I know that JavaScript uses UCS-2, so does that mean 2 bytes per character. However, does it depend on the JavaScript…
Paul Biggar
  • 27,579
  • 21
  • 99
  • 152
143
votes
2 answers

Save byte array to file

I have a byte array (an IEnumerable actually), and I need to save it to a new file containing this data. How do I do that? I found some answers telling how to create a MemoryStream from that, but still can't save it to a brand new file.
Daniel Möller
  • 84,878
  • 18
  • 192
  • 214
142
votes
2 answers

What does a b prefix before a python string mean?

In a python source code I stumbled upon I've seen a small b before a string like in: b"abcdef" I know about the u prefix signifying a unicode string, and the r prefix for a raw string literal. What does the b stand for and in which kind of source…
kriss
  • 23,497
  • 17
  • 97
  • 116
140
votes
2 answers

How many bits or bytes are there in a character?

How many bits or bytes are there per "character"?
RedKing
  • 1,563
  • 4
  • 12
  • 10
133
votes
14 answers

Byte array to image conversion

I want to convert a byte array to an image. This is my database code from where I get the byte array: public void Get_Finger_print() { try { using (SqlConnection thisConnection = new SqlConnection(@"Data Source=" +…
Tanzeel ur Rahman
  • 1,431
  • 2
  • 9
  • 4
127
votes
14 answers

What's the difference between a word and byte?

I've done some research. A byte is 8 bits and a word is the smallest unit that can be addressed on memory. The exact length of a word varies. What I don't understand is what's the point of having a byte? Why not say 8 bits? I asked a prof this…
user796388
126
votes
4 answers

Why is "int i = 2147483647 + 1;" OK, but "byte b = 127 + 1;" is not compilable?

Why is int i = 2147483647 + 1; OK, but byte b = 127 + 1; is not compilable?
goku
  • 1,197
  • 1
  • 10
  • 14
124
votes
5 answers

How to create python bytes object from long hex string?

I have a long sequence of hex digits in a string, such as 000000000000484240FA063DE5D0B744ADBED63A81FAEA390000C8428640A43D5005BD44 only much longer, several kilobytes. Is there a builtin way to convert this to a bytes object in python 2.6/3?
recursive
  • 83,943
  • 34
  • 151
  • 241
122
votes
4 answers

What does value & 0xff do in Java?

I have the following Java code: byte value = 0xfe; // corresponds to -2 (signed) and 254 (unsigned) int result = value & 0xff; The result is 254 when printed, but I have no idea how this code works. If the & operator is simply bitwise, then why…
dagronlund
  • 1,612
  • 3
  • 13
  • 15
118
votes
14 answers

How to convert a byte to its binary string representation

For example, the bits in a byte B are 10000010, how can I assign the bits to the string str literally, that is, str = "10000010". Edit I read the byte from a binary file, and stored in the byte array B. I use…
Sean
  • 4,267
  • 10
  • 36
  • 50