Flux rss
 

Binary encoding

Introduction to binary

In the late 1930s, Claude Shannon showed that by using switches which were closed for "true" and open for "false," it was possible to carry out logical operations by assigning the number 1 to "true" and 0 for "false."

This information encoding system is called binary. It's the form of encoding that allows computers to run. Binary uses two states (represented by the digits 0 and 1) to encode information.

Since 2000 BCE, humans have counted using 10 digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9). This is called "decimal base" (or base 10). However, older civilisations, and even some current applications, used and still use other number bases:

  • Sexagesimal (60), used by the Sumerians. This base is also used in our current system of timekeeping, for minutes and seconds;
  • Vicesimal (20), used by the Mayans;
  • Duodecimal (12), used in the monetary systems of the United Kingdom and Ireland until 1971: A "pound" was worth twenty "shillings," and a "shilling" was worth twelve "pence". The current system of timekeeping is also based around twelve hours (particularly in American usage);
  • Quinary (5), used by the Mayans;
  • Binary (2), used by all digital technology.

The bit

The term bit (shortened to a lowercase b) means "binary digit", meaning 0 or 1 in binary numbering. It is the smallest unit of information which can be manipulated by a digital machine. It is possible to represent this binary information:

  • with an electrical or magnetic signal, which, beyond a certain threshold, stands for 1;
  • By the roughness of bumps in a surface;
  • using flip-flops, electrical components which have two stable states (one standing for 1, the other 0).

Therefore, a bit can be set to one of two states: either 1 or 0. With two bits, you can have four different states (2*2):

0 0
0 1
1 0
1 1

With 3 bits, you can have eight different states (2*2*2):

3-bit binary value Decimal value
000 0
001 1
010 2
011 3
100 4
101 5
110 6
111 7

For a group of n bits, it is possible to represent 2n values

Bit values

In a binary number, a bit's value, depends on its position, starting from the right. Like tens, hundreds, and thousands in a decimal number, a bit's value grows by a power of two as it goes from right to left, as shown in the following chart:

Binary number11111111
value27 = 12826 = 6425 = 3224 = 1623 = 822 = 421 = 220 = 1

Conversion

To convert a binary string into a decimal number, multiply the value of each bit by its weight, then add together the products. Therefore, the binary string 0101, in decimal, comes to:

23x0 + 22x1 + 21x0 + 20x1
= 8x0 + 4x1 + 2x0 + 1x1
= 5

The byte

The byte (shortened to uppercase B) is a unit of information composed of 8 bits. It can be used to store, among other things, a character, such as a letter or number.

Grouping numbers in clusters of 8 makes them easier to read, much as grouping numbers in threes helps to make thousands clearer when working in base-10. For example, the number "1,256,245" is easier to read than "1256245".

A 16-bit unit of information is usually called a word.

A 32-bit unit of information is called a double word (sometimes called a dword).

For a byte, the smallest number possible is 0 (represented by eight zeroes, 00000000), and the largest is 255 (represented by eight ones, 11111111), making for 256 different possible values.

27 =128 26 =64 25 =32 24 =16 23 =8 22 =4 21 =2 20 =1
0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1

Kilobytes and Megabytes

For a long time, computer science was unusual it that it used different values for its units than metric system (also called the International System). Computer users would often learn that 1 kilobyte was made up of 1024 bytes. For this reason, in December 1998, the International Electrotechnical Commission weighed in on the issue (http://physics.nist.gov/cuu/Units/binary.html). Here are the IEC's standardised units:

  • One kilobyte (kB) = 1000 bytes
  • One megabyte (MB) = 1000 kB = 1,000,000 bytes
  • One gigabyte (GB) = 1000 MB = 1,000,000,000 bytes
  • One terabyte (TB) = 1000 GB = 1,000,000,000,000 bytes

Note Warning! Some software (and even some operating systems) still use the pre-1998 notation, which is as follows:
  • One kilobyte (kB) = 210 bytes = 1024 bytes
  • One megabyte (MB) = 220 bytes = 1024 kB = 1,048,576 bytes
  • One gigabyte (GB) = 230 bytes = 1024 MB = 1,073,741,824 bytes
  • One terabyte (TB) = 240 bytes = 1024 GB = 1,099,511,627,776 bytes

The IEC has also defined binary kilo (kibi), binary mega (mebi), binary giga (gibi), and binary tera (tebi).
They are defined as:

  • One kibibyte (kiB) is worth 210 = 1024 bytes
  • One mebibyte (MiB) is worth 220 = 1,048,576 bytes
  • One gibibyte (GiB) is worth 230 = 1,073,741,824 bytes
  • One tebibyte (TiB) is worth 240 = 1,099,511,627,776 bytes

In some languages, such as French and Finnish, the word for byte does not begin with "b", but the international community, on the whole, generally prefers the English term "byte." This gives the following notations for kilobyte, megabyte, gigabyte, and terabyte:

kB, MB, GB, TB
Note Note the use of an uppercase B to distinguish Byte from bit.

This is a screenshot from the software HTTrack,the most popular offline web browser, showing how this notation is used:

HTTrack screenshot

Binary operations

Simple arithemtic operations such as addition, subtraction, and multiplication are easily performed in binary.

Addition in binary

Addition in binary follows the same rules as in decimal:
Start by adding the lowest-valued bits (those on the right) and carry the value over to the next place when the sum of two bits in the same position is greater than the largest value of the unit (in binary: 1). This value is then carried over to the bit in the next position.

For example:

  0 1 1 0 1
+ 0 1 1 1 0
- - - - - -
  1 1 0 1 1

Multiplication in binary

The multiplication table in binary is simple:

  • 0x0=0
  • 0x1=0
  • 1x0=0
  • 1x1=1

Multiplication is performed by calculating a partial product for each multiplier (only the non-zero bits will give a non-zero result) When the bit of the multiplier is zero, the partial product is null; when it is equal to one, the partial product is formed from the multiplicand, shifted X places, where X is equal to the weight of the multiplier bit.

For example:

    0 1 0 1 multiplicand
x   0 0 1 0 multiplier
- - - - - -
    0 0 0 0
  0 1 0 1  
0 0 0 0    
- - - - - -
  0 1 0 1 0


Last update on Thursday October 16, 2008 02:43:14 PM.
This document entitled « Binary encoding » from Kioskea (en.kioskea.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the licence, as this note appears clearly.

Results for

Error checking Binary encoding is very practical for use in electronic devices such as computers, in which information can be encoded based on whether an electrical signal is present or not. However, this electrical signal may suffer disturbances (such as... en.kioskea.net/base/control.php3
BinHex encoding BinHex encoding (a contraction of binary-to-hexadecimal) is a proprietary algorithm owned by Apple for converting 8-bit binary data into a 7-bit format. BinHex encoding, designed for Macintosh systems, is used to preserve file attributes, and... en.kioskea.net/base/binhex.php3
Uuencode/Uudecode UUencode encoding (a contraction of Unix-to-Unix encode) is an algorithm for converting 8-bit binary data into a 7-bit format. Uuencoding was originally created for sending binary files using the email protocol uucp. The uucp system translated the... en.kioskea.net/base/uuencode-uudecode.php3

Results for

How to read and create a BIN and CUE file?How to read and create a BIN and CUE file? What is a BIN file? How to create BIN and CUE files How to burn BIN and CUE files How to read/convert BIN and CUE files What is a BIN file? A BIN and CUE file together create a binary... en.kioskea.net/faq/sujet-264-how-to-read-and-create-a-bin-and-cue-file
Playing RMVB filesPlaying RMVB files RMVB FILE is the acronym for RealMedia Variable Bitrate. RealMedia Variable bitrate is the audio and video encoder for the RealMedia multi media container format. It is one of the recent audio video formats commonly used due to... en.kioskea.net/faq/sujet-234-playing-rmvb-files
Convert your video file to and from .flvConvert your video file to and from .flv Introduction Under Windows Riva FLV Encoder: Super: Under Linux Operating Systems Introduction This tips has been drawn to explain how to convert your video files from any files type to .flv... en.kioskea.net/faq/sujet-822-convert-your-video-file-to-and-from-flv

Results for

Unable to install windowsHello, when trying to install windows xp everything is alright but then after it gives me a blue sceen with some errors on that in forms of binary codes.. anyone can help me please? en.kioskea.net/forum/affich-21198-unable-to-install-windows
How data is formattedHello, Which layer defines how data is formatted, presented, encoded, and converted for use on the network ? en.kioskea.net/forum/affich-2744-how-data-is-formatted
Vista audio problemHello, ahhh, I found this, but it didn't work/ I must not have the specific area to add the binary 'EnableInputMonitor' value, but this works for some people, any advice? johne@email.com In regedit go to:... en.kioskea.net/forum/affich-9905-vista-audio-problem

Results for

Download K-Lite Codec Pack FullK-Lite Codec Pack is a collection of VFW/ACM codecs, DirectShow filters and tools. Codecs and DirectShow filters are needed for encoding and decoding (playing) audio and video formats. Contents of version 4.2.5 : Player: Media Player... en.kioskea.net/telecharger/telecharger-45-k-lite-codec-pack-full
Download Easy Video Downloader Easy Video Downloader is a complete program not only for the downloading of video on Internet, but also an encoder. In order to do that, you only have to choose URL of video, to glue together it on the interface of program and to begin... en.kioskea.net/telecharger/telecharger-437-easy-video-downloader
Download FfmpegXEncoding will not be any more a mystery for whoever. FfmpegX is the horrible tool of encoding par excellence. It is a graphic interface indicated for Mac. Encoding becomes with more than 20 tools Open Source different including the ffmpeg... en.kioskea.net/telecharger/telecharger-204-ffmpegx

Results for

Representation of real numbers and integers Representing (or encoding) a number means to express it in binary form. Representing numbers in a computer is necessary in order for it to be able to store and manipulate them. However, the problem is that a mathematical number can be infinite (as... en.kioskea.net/base/representation.php3
Base64 encoding The concept of Base64 encoding entails using US-ASCII (non-accented) characters to encode any sort of data in 8-bit form. Email protocols were originally designed to send messages in plain text only. But as email systems vary greatly, transferring... en.kioskea.net/base/base64.php3
Quoted-printable encoding Quoted-printable encoding (somtimes QP) involves using US-ASCII 7-bits encoding (non-accented letters) to encode a text that requires an alphabet of 8-bit characters (accented letters), such as ISO-Latin-1, which is used for most Western European... en.kioskea.net/base/quoted-printable.php3