Friday, February 17, 2023

Binary and Hexadecimal

Number Systems

There are three numbering systems that use a network engineer need to know:

  • Decimal (Base 10) – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  • Binary (Base 2) – 0 or 1
  • Hexadecimal (Base 16) - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

Binary Conversion to Decimal

  • Binary is a fundamental building block in networks today.
  • You need to understand binary if you want to be able to work with networks.
  • Be aware that you need to know binary to work with access lists or access control lists that allow you to permit or deny traffic based on an IP address.
  • When you configure devices in your network with various IP addresses, you may want to permit one device to talk to another device, but then deny a third device from talking to that second device.
  • Now, to do that, you permit or deny traffic based on a IP address, whether that's a source IP address or a destination IP address. You're going to match specific IP addresses based on a binary representation.
  • Computers, networking devices and machines use binary. That's what they understand.
  • And for you to implement things like access control lists in a network or something like a subnet mask. So, determining what a subnet mask is for a specific network, you need to understand binary.
  • Now, as an analogy, to help us understand binary, let's use the analogy of electricity, because computers, let's be honest, they have chips in them. Routers and switches, have specific types of chips known as ASICs or Application Specific Integrated Circuits. It's basically a circuit. So, computers have circuits and they run on electricity.
  • In electricity, we have two states. Something is on as in this current or power to the device or it's off.
All computers function by using a system of switches that can either be on or off.

Off = 0
On = 1
Binary values = 0 or 1

  • So, think about it like this when you need to send a signal to a computer and you need to indicate 1 you apply current, when you want to indicate 0 you don't apply current.
  • We might write a program in a high-level programming language like Python but as it goes down, we end up doing assembly language. We end up writing 0s and 1s to tell the computer what it needs to do.

So, we have 2 states i.e., 0 or 1.

  • If we have 2 states and 1 cable, we can have 2 binary values as 0 or 1. (21 = 2)
  • If we have 2 state and 2 cable, we will have 4 binary values as: (22 = 4)
    • 00
    • 01
    • 10
    • 11
  • IF we have 2 state and 3 cable, we will have 8 binary values as (23 = 8)
    • 000
    • 001
    • 010
    • 011
    • 100
    • 101
    • 110
    • 111
Similarly, if we have 2 states and n cable, we will have 2n binary values
So, as for IPv4 we have 8 bits of binary values for each octet as:
00000000. 00000000. 00000000. 00000000
So, we will have 28 = 256 binary values for each octet of IPv4.
As in binary, we start with zero values.

Table to be Remember

BaseExponent

27

26

25

24

23

22

21

20

Binary

1

1

1

1

1

1

1

1

Decimal

128

64

32

16

8

4

2

1

  • 128 + 64 + 32+ 16 + 8 + 4 + 2 +1 = 255
  • Or we can write as:
  • 11111111 in Binary = 255 in Decimal

Let take 1 example,

What is the binary equivalent of 192 in decimal?

BaseExponent

27

26

25

24

23

22

21

20

Binary

1

1

0

0

0

0

0

0

Decimal

128

64

32

16

8

4

2

1

  • 128 + 64 = 192
  • Or we can write as:
  • 11000000 in Binary = 192 in Decimal

Hexadecimal Conversion to Decimal

  • Well, we care about hexadecimal because it's used in networking all over the place, as an example. When you, look at the MAC address of a device it's written in hexadecimal.
  • MAC addresses are written in hexadecimal, what's really becoming important these days is IPv6, IPv6 addresses are also written in hexadecimal.
  • So, you'll see an IP address such as:
    • FE80::1
    • 2001::123/64
  • You need to be able to interpret IPv6 addresses.
  • You need to know how to convert hexadecimal to binary, binary to hexadecimal, hexadecimal to decimal, decimal to hexadecimal and all those different combinations.

Comparison between Hexadecimal, Binary and Decimal

Hexadecimal

Binary

Decimal

0

0000

0

1

0001

1

2

0010

2

3

0011

3

4

0100

4

5

0101

5

6

0110

6

7

0111

7

8

1000

8

9

1001

9

A

1010

10

B

1011

11

C

1100

12

D

1101

13

E

1110

14

F

1111

15

For example,

Consider a decimal value: 128
For 128 – Binary value is 1000 0000
We have divided the 128 binary value in group of four.
So, from the above table if we look for 1000 decimal value is 8, and for 0000 is 0
So, the hexadecimal value will be 80 for decimal 128

Few more example:

Hexadecimal

Binary

Decimal

255

1111 1111

FF

224

1110 0000

E0

240

1111 0000

F0

244

1111 0100

F4

No comments:

Post a Comment