Search Logic Blocks

Thursday, January 9, 2020

Bits, Bytes and Binary Values

Let's go to computer basics. Have you ever thought how computer works? How  the information is stored on the computer? Have you heard about bits and bytes? What are bits and bytes? I mentioned bits when I wrote about data types. Let's explore more about bit and its significance -

Bits - Bit is short form of binary digit. Like decimal digits are 0-9, binary digits (bits) are only two digits - 0 and 1. And you will be surprised to know that all informations stored in digital form is represented by bits only. A bit is the smallest unit of information on a machine. In decimal digits, we have base 10 counting. In binary digits, we use base 2 counting. By combining bits you can obtain larger units. In decimal digits, we have base 10 counting. For example: 32-bit addresses, 64-bit addresses, 1-bit image (monochrome), 8-bit image (256 colors / grayscales) and 24- or 32-bit graphics. You can have so many examples of bits.

Nibbles - Combination of 4 bits is called a nibble. In binary counting, we can have any number of digits, but only in 0s and 1s. Nibble values have range from 0 (0000) to 15 (1111). See the following chart, how we can convert binary values into decimal.

Nibble Convert To Decimal Evaluate Value
0000 0 X 23 + 0 x 22 + 0 x 21 + 0 x 20 0 + 0 + 0 + 0 0
0001 0 X 23 + 0 x 22 + 0 x 21 + 1 x 20 0 + 0 + 0 + 1 1
0010 0 X 23 + 0 x 22 + 1 x 21 + 0 x 20 0 + 0 + 2 + 0 2
0011 0 X 23 + 0 x 22 + 1 x 21 + 1 x 20 0 + 0 + 2 + 1 3
0100 0 X 23 + 1 x 22 + 0 x 21 + 0 x 20 0 + 4 + 0 + 0 4
0101 0 X 23 + 1 x 22 + 0 x 21 + 1 x 20 0 + 4 + 0 + 1 5
0110 0 X 23 + 1 x 22 + 1 x 21 + 1 x 20 0 + 4 + 2 + 0 6
0111 0 X 23 + 1 x 22 + 1 x 21 + 1 x 20 0 + 4 + 2 + 1 7
1000 1 X 23 + 0 x 22 + 0 x 21 + 0 x 20 8 + 0 + 0 + 0 8
1001 1 X 23 + 0 x 22 + 0 x 21 + 1 x 20 8 + 0 + 0 + 1 9
1010 1 X 23 + 0 x 22 + 1 x 21 + 0 x 20 8 + 0 + 2 + 0 10
1011 1 X 23 + 0 x 22 + 1 x 21 + 1 x 20 8 + 0 + 2 + 1 11
1100 1 X 23 + 1 x 22 + 0 x 21 + 0 x 20 8 + 4 + 0 + 0 12
1101 1 X 23 + 1 x 22 + 0 x 21 + 1 x 20 8 + 4 + 0 + 1 13
1110 1 X 23 + 1 x 22 + 1 x 21 + 0 x 20 8 + 4 + 2 + 0 14
1111 1 X 23 + 1 x 22 + 1 x 21 + 1 x 20 8 + 4 + 2 + 1 15

Bytes - Combination of 8 bits is called a byte. A byte can have values from 0 (0000 00000) to 255 (1111 1111). Let's see what value is for 1010 0101


1 0 1 0 0 1 0 1
1 x 27 0 x 26 1 x 25 0 x 24 0 x 23 1 x 22 0 x 21 1 x 20
128 0 32 0 0 4 0 1

Value for Byte 1010 0101 is = 128 + 32 + 4 + 1 = 165 

How to convert decimal to binary value?
To convert decimal value to the binary value (bits), we should divide the number successively by 2 and get the remainders as 0s and 1s. Let's see an example here, converting 237 into binary value :


Divide by 2 Quotient Remainder 2 to the power
237 / 2 118 1 20
118 / 2 59 0 21
59 / 2 29 1 22
29 / 2 14 1 23
14 / 2 7 0 24
7 / 2 3 1 25
3 / 2 1 1 26
1 / 2 0 1 27

So, binary value for the number 237 is 1110 1101. Let's confirm this - 


1 1 1 0 1 1 0 1
1 x 27 0 x 26 1 x 25 1 x 24 0 x 23 1 x 22 0 x 21 1 x 20
128 64 32 0 8 4 0 1

128 + 64 + 32 + 8 + 4 + 1 = 237

Example 1: What is the binary value of decimal number 219?

Solution : 

Divide by 2QuotientRemainder2 to the power
219 / 2109120
109 / 254121
54 / 227022
27 / 213123
13 / 26124
6 / 23025
3 / 21126
1 / 20127

So, binary value for the number 219 is 1101 1011. Let's confirm this - 


11011011
1 x 271 x 260 x 251 x 241 x 230 x 221 x 211 x 20
128640168021

128 + 64 + 16 + 8 + 2 + 1 = 219

Example 2: What is the decimal value of binary value 1100 0011?

Solution : 

1
1
0
0
0
0
1
1
1 x 27
1 x 26
0 x 25
0 x 24
0 x 23
0 x 22
1 x 21
1 x 20
128
64
0
0
0
0
2
1

128 + 64 + 2 + 1 = 195

No comments: