[Networking Series 2/3] Bits, Bytes and more

Various topics with in depth explanation

Moderator: Moderator Group

Forum rules
If you have questions please do not respond to the topics and create a new one on in the Pandoras Box or Widget Designer forums instead. Comments to information given are always welcome, though.

[Networking Series 2/3] Bits, Bytes and more

Postby Dennis Kuypers » Wed Jul 25, 2018 10:38 pm

If you break down how a computer works, it's basically just ones and zeros (power on OR power off). We can express this using the binary system.
Mostly we are interested in larger numbers than just 0 or 1 can express on their own. The smallest unit we mostly talk about is called...

A Byte
A byte consists of 8 bits. The largest number we can get when using 8 bits (or 8 digits in the binary system) is 111111112 = 255. If we add the 0 we have 256 possible values. The hexadecimal system offers a convenient way to express one byte (for example 255) as 0xFF. Now a byte can only "store" values from 0-255 - what if we want higher values? We can use...

An Integer (lat. for "whole" as in "whole numbers"/"no fractions") comes in different sizes, we usually have either one byte - which we just call a byte - or we combine multiple bytes:
  • 2 bytes = 16 bits = "short" or "int16"
  • 4 bytes = 32 bits = just "int" or "int32"
  • 8 bytes = 64 bits = "int64"

Now we might want to store or transmit negative values. This can be done by using the first bit as the sign (first bit decides wether the number is positive or negative). That leaves us with 7bits for the actual value when using bytes, 15bits when using a "short", etc...
We call these signed or unsigned Please note that the "default" version of each integer is the signed version. The only exception to this rule is the byte which is unsigned. If you want to express the "signedness" of the datatype use these names:

signed: "sbyte" or "int8", "short" or "int16", "integer" or "int32", "int64"
unsigned: "byte" or "uint8", "ushort" or "uint16", "uint" or "uint32", "uint64"

Bonus: Decimal numbers
These are called "floats" and the most used one is called a "double". They are rather complicated compared to integers - if you're interested, there are many good resources on the web.
Dennis Kuypers
Product Developer, Software

Online Manual
User avatar
Dennis Kuypers
coolux Germany
Posts: 764
Joined: Thu Jul 05, 2012 12:18 pm

Return to Good to know

Who is online

Users browsing this forum: No registered users and 0 guests