Page 1 of 1

Question On Bytes and Sockets

Posted: Thu Jun 03, 2010 7:58 pm
by davidthefat
So exactly what is a byte? :lol: IDK how to ask this, but is it a hex? or binary? or what? When the arguement takes in a byte, WTF can I put into there? Im asking for Java, and C++. My server is programmed in Java (its a robot, and it uses java...) and the client is in C++, so will it have problems when sending and receiving a socket with ints or floats and doubles? They don't have the same "standards" from what I know, or is it just better to send a giant string? I am trying to transfer an array of doubles to the PC from the robot through sockets. IDK if I should send the values one by one and check if they are the same and then send the other one or not check at all?

I am trying to render a 3d image captured from the robot on the client PC's screen using OpenGL and SDL. I got the getting the image part down, and the drawing part, but not the communication, which is one vital factor that can render this useless.

Re: Question On Bytes and Sockets

Posted: Thu Jun 03, 2010 8:07 pm
by avansc
davidthefat wrote:So exactly what is a byte? :lol: IDK how to ask this, but is it a hex? or binary? or what? When the arguement takes in a byte, WTF can I put into there? Im asking for Java, and C++. My server is programmed in Java (its a robot, and it uses java...) and the client is in C++, so will it have problems when sending and receiving a socket with ints or floats and doubles? They don't have the same "standards" from what I know, or is it just better to send a giant string? I am trying to transfer an array of doubles to the PC from the robot through sockets. IDK if I should send the values one by one and check if they are the same and then send the other one or not check at all?

I am trying to render a 3d image captured from the robot on the client PC's screen using OpenGL and SDL. I got the getting the image part down, and the drawing part, but not the communication, which is one vital factor that can render this useless.
a byte is just a word that means 8 sequential bits. the byte int binary 1111 1111 is FF in hex and 255 in decimal (unsigned of course.)
a nibble is half a byte, so 4 bits.

Re: Question On Bytes and Sockets

Posted: Thu Jun 03, 2010 8:11 pm
by davidthefat
avansc wrote: a byte is just a word that means 8 sequential bits. the byte int binary 1111 1111 is FF in hex and 255 in decimal (unsigned of course.)
a nibble is half a byte, so 4 bits.
;) Thanks I can always rely on you, so I can just send raw Binary or Hex though it?

Re: Question On Bytes and Sockets

Posted: Thu Jun 03, 2010 8:55 pm
by short
davidthefat wrote:
avansc wrote: a byte is just a word that means 8 sequential bits. the byte int binary 1111 1111 is FF in hex and 255 in decimal (unsigned of course.)
a nibble is half a byte, so 4 bits.
;) Thanks I can always rely on you, so I can just send raw Binary or Hex though it?
You can't send raw binary or hex through it, binary and hex are just a way of viewing the data.. You can send bytes though. Open up your calculator and you can see this, a number can be viewed in base 2 (binary) base 10 (decimal) or base 16 (hexadecimal) however the data, no matter how your viewing it, is the same. recap: you send bytes, you can view those bytes in binary, hex, whatever.

Re: Question On Bytes and Sockets

Posted: Thu Jun 03, 2010 8:57 pm
by davidthefat
short wrote:
davidthefat wrote:
avansc wrote: a byte is just a word that means 8 sequential bits. the byte int binary 1111 1111 is FF in hex and 255 in decimal (unsigned of course.)
a nibble is half a byte, so 4 bits.
;) Thanks I can always rely on you, so I can just send raw Binary or Hex though it?
You can't send raw binary or hex through it, binary and hex are just a way of viewing the data.. You can send bytes though. Open up your calculator and you can see this, a number can be viewed in base 2 (binary) base 10 (decimal) or base 16 (hexadecimal) however the data, no matter how your viewing it, is the same. recap: you send bytes, you can view those bytes in binary, hex, whatever.
I see, I was just confusing my self, I can just send a string or a int or other primitive types through a socket

Re: Question On Bytes and Sockets

Posted: Thu Jun 03, 2010 8:58 pm
by Live-Dimension
Yes, you can.
davidthefat wrote:
avansc wrote: a byte is just a word that means 8 sequential bits. the byte int binary 1111 1111 is FF in hex and 255 in decimal (unsigned of course.)
a nibble is half a byte, so 4 bits.
;) Thanks I can always rely on you, so I can just send raw Binary or Hex though it?
1111 1111 is FF is 255. They are exactly the same.

If you send a byte through (an unsigned char) which has a value of 255, really you are sending 1111 1111 over the network. The hex representation of that is FF. It's just another way to look at the same data. You can send the "hex" representation as a char array, but thats two bytes. unsigned char[2] = 'F', 'F'. It's slower to transmit and you have to encode it and de-encode it.

Just send it as binary. It's far quicker obviously ;)

Re: Question On Bytes and Sockets

Posted: Thu Jun 03, 2010 9:28 pm
by davidthefat
:lol: Seems like I was looking at the parent classes, I went down the "family tree" and found the class I needed, it has everything from int to float and doubles

Re: Question On Bytes and Sockets

Posted: Fri Jun 04, 2010 4:40 am
by K-Bal
avansc wrote: a byte is just a word that means 8 sequential bits.
The standard just tells that a byte is the smallest word. It does not tell how much bits it has. Just for completeness ;)

Re: Question On Bytes and Sockets

Posted: Fri Jun 04, 2010 12:25 pm
by Milch
K-Bal wrote:
avansc wrote: a byte is just a word that means 8 sequential bits.
The standard just tells that a byte is the smallest word. It does not tell how much bits it has. Just for completeness ;)
I think ANSI-C99 reads that a byte are ATLEAST 8 bits :)

Re: Question On Bytes and Sockets

Posted: Sun Jun 06, 2010 8:27 pm
by avansc
K-Bal wrote:
avansc wrote: a byte is just a word that means 8 sequential bits.
The standard just tells that a byte is the smallest word. It does not tell how much bits it has. Just for completeness ;)
Ummm.. wel i might be wrong here, but as far as i know a byte is a byte. It is always 8 bits on any arch.

a word is USUALLY half of what a int is. which is 2 bytes or 16 bits on most archs. "short" is a synonym for word.

you can test it out if you want, printf("%d\n", sizeof(short)); printf("%d\n", sizeof(int));

if you program in asm you actually use "word", DW for a word in x86 asm.

Re: Question On Bytes and Sockets

Posted: Sun Jun 06, 2010 8:50 pm
by Live-Dimension
avansc wrote:
K-Bal wrote:
avansc wrote: a byte is just a word that means 8 sequential bits.
The standard just tells that a byte is the smallest word. It does not tell how much bits it has. Just for completeness ;)
Ummm.. wel i might be wrong here, but as far as i know a byte is a byte. It is always 8 bits on any arch.
Most platforms are 8bits/byte, but not all.

http://en.wikipedia.org/wiki/Byte
The byte (pronounced /ˈbaɪt/) is a unit of digital information in computing and telecommunications. It is an ordered collection of bits, in which each bit denotes the binary value of 1 or 0. Historically, a byte was the number of bits (typically 5, 6, 7, 8, 9, or 16) used to encode a single character of text in a computer and it is for this reason the basic addressable element in many computer architectures. The size of a byte is typically hardware dependent, but the modern de facto standard is 8 bits, as this is a convenient power of 2. Most of the numeric values used by many applications are representable in 8 bits and processor designers optimize for this common usage. Signal processing applications tend to operate on larger values and some digital signal processors have 16 or 40 bits as the smallest unit of addressable storage (on such processors a byte may be defined to contain this number of bits). The term octet was explicitly defined to denote a sequence of 8 bits because of the ambiguity associated with the term byte and is widely used in communications protocol specifications.
It is however not so simple.
The C and C++ programming languages, for example, define byte as "addressable unit of data large enough to hold any member of the basic character set of the execution environment" (clause 3.6 of the C standard). The C standard requires that the char integral data type is capable of holding at least 255 different values, and is represented by at least 8 bits (clause 5.2.4.2.1). Various implementations of C and C++ define a byte as 8, 9, 16, 32, or 36 bits. The actual number of bits in a particular implementation is documented as CHAR_BIT as implemented in the limits.h file. Java's primitive byte data type is always defined as consisting of 8 bits and being a signed data type, holding values from −128 to 127.