DEV Community

Anja
Anja

Posted on

1 1

What is a Bit?

A bit (binary digit) is the smallest unit of data in a computer. A bit has either the value 0 or 1. 0 represents the electrical signal “off” and 1 “on”. The binary numeral system uses the base 2. Lets take a look at an example. Here we have a byte, which consists of 8 bits. It has these values:

0000  1    1    0    1
(...) 2^3  2^2  2^1  2^0
Enter fullscreen mode Exit fullscreen mode

The 8 bits/1 byte 00001101 equals the number 13. Because the rightmost number is 1, we know that we have to calculate 2 to the power of 0, which is 1. So we need to remember the 1. To the left we have 0, so we know that we don`t add 2^1.

Then to the left we have another 1, so we have to calculate 1+2^2, which is 5. Remember the 5 now. Next we have a 1, so we need to add 2^3 to the five, so 5+2^3 is 13.

As all the following bits are set to 0, we dont have to calculate anything there. It would have continued with 2^4, 2^5,2^6 and 2^7. Easy, right? :) While programming, have you worked with bits yet?

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay