Number System C - Decimal, Binary, Octal and Hex (2023)

In this tutorial we will learn about the different number systems.

Introduction:

On computers, we typically use four different numbering systems:Decimal, Binary, Octal and Hexadecimal.

Isdecimal systemIt is a number system used in our daily applications like business etc. In this system, the symbols 0,1,2,3,4,5,6,7,8,9 are used to denote different numbers.

insidebinary number system,0j1They are the only symbols used to represent numbers of all magnitudes. For example a normal decimal number7 (seven)It is represented in binary as111. The binary system is mainly used in computers and other computing devices.

A number in a certain base is written as(Number)Base. For example,(17)10is a decimal number (seventeen) and(10001)2is a binary number 10001, which actually represents a decimal number whose value is17.

Because the decimal number system is more commonly used, theDecimal (35)10it is simply written as 35. However, if the same number is to be represented in theSensesystem, it is written as(100011)2.

Likewise theoctalUse of the number system8as a base. Typically used to indicate digits and represent file permissions on UNIX/Linux operating systems.

hexadecimalsystem thatHexis a number system that usessixteenas a basis for representing numbers.

1. Decimal Numbers:

The numbers we use every day are among thedecimal system. For example 0,1,2,3,4,…..,9999,…..etc. It is also called aBasis – System 10.

it's called theBasis-10Number system because it uses10 unique digitsvon0 bis 9to represent any number.

ABase(also called theBase) is the number of unique digits or symbols (including 0) used to represent a specific number.

in onedecimal system(where the base is 10), a total of 10 digits (0,1,2,3,4,5,6,7,8, and 9) are used to represent any number of any size. For example,A hundred and thirty fiveis represented as135, Wo

135 = (1 * 102) + (3 * 101) + (5 * 100)

135 = (1 * 100) + (3 * 10) + (5 * 1)

Similarly, fractions are represented using the base: 10 raised to a negative power.

2. Binary Numbers:

Isbinary number systemIt is used in both mathematics and digital electronics.The binary number systemÖBase - 2 number systemrepresents numeric values ​​with only two symbols:Null (0)jLike 1).

Computers have circuits (logic gates) that can be in one of two states:OUT OFÖIN. These two states are represented byNull (0)jLike 1)or For this reason, the calculation is carried out in systems with a binary number system (base – 2), in which all numbers are represented with 0 and 1.

Everybinary number, also Null (0) from uno (1) is calledBit(known asBI am youIs). A collection of8such bits are calledByte.

In computer terminology, multiples of different names have been given210(That means.,1024multiplied by the currently existing value), as shown in the following table:

Number System C - Decimal, Binary, Octal and Hex (1)

In the computer, texts, pictures, music, videos or any kind of data are ultimately stored in binary format on the hard drive.

In the binary system, a total of 2 digits (0 and 1) are used to represent a number of any size.

For example,Nullis represented as 0, where

0 = (0 * 20) = (0 * 1)

Similar,Likeis represented as 1, where

1 = (1 * 20) = (1 * 1)

Now let's represent the following numbers in binary format:

Of the(2): Since 0 and 1 are the only digits that can be used to represent 2, we divide 2 by 2 and write the quotient and the remainder as follows:

[Quotient][Rest], also : [1][0]

2 = (1 * 21) + (0 * 20) = (2) + (0)

Three(3): Since 0 and 1 are the only digits that can be used to represent 3, we divide 3 by 2 and write the quotient and the remainder as follows:

[Quotient][Rest], also :[1][1]

3 = (1 * 21) + (1 * 20) = (2) + (1)

Seventeen(17): Since 0 and 1 are the only digits that can be used to represent 17, we divide 17 by 2 and write the quotient and the remainder as follows:

[quotient][remainder], i.e.:[8][1], repeating the above logic for 8(8 = [4][0]), 4(4 = [2][0]),2(2 = [ 1][0]) and 1(1 = [0][1]), we finally get [1][0][0][0][1].

17 = (1 * 24) + (0 * 23) + (0 * 22) + (0 * 21) + (1 * 20)

17 = (16) + (0) + (0) + (0) + (1)

InC,Binary numbers are prefixed0b (or 0B)(Number zero followed by the letter 'b'). For example, to store a binary value of four in a variablebinary_four,We write

int binary_Four = 0b100;

3. Octal Numbers:

The numbering system you are usingBasis-8it's called theoctal system.A base (aka root) is the number of unique digits or symbols (including 0) used to represent a given number.

In the octal (or base-8) system, a total of 8 digits (0, 1, 2, 3, 4, 5, 6, and 7) are used to represent a number of any size (size).

For example,Nullis represented as0, Wo

0 = (0* 80) = (0* 1)

In the same way, the numbers 1, 2, … and 7 are represented below:

1 = (1* 80) = (1* 1)

2 = (2* 80) = (2* 1)

……

7 = (7* 80) = (7* 1)

Now let's represent the following numbers in the octal system:

Eighteen(18): Since 0 through 7 are only digits that can be used to represent 18, we divide 18 by 8 and write the quotient and the remainder as follows:

[Quotient][Rest], also:[2][2]

18 = (2* 81) + (2* 80) = (16) + (2)

Four hundred twenty one(421): Since 0 through 7 are only digits that can be used to represent 421, we divide 421 by 8 and write the quotient and the remainder as follows:

[Quotient][Rest], also: [52][5](Dividing plus 52 by 8 gives us[6][4]), which[6][4][5]

421 = (6 * 82) + (4 * 81) + (5 * 80) = (384) + (32) + (5)

To distinguish them from decimal numbers, octal numbers are prefixed.0(null).

For example, to store an octal value of seven in a variableoctal_seven, We write

int octal_seven = 07;

Similarly, if we want to store an octal representation of a decimal number 9 in a variablenumber nine,We write

int number_nine = 011;

The largest digit in the octal system is(7)8. number 7)8In binary format it is represented as(111)2. In the binary system, three binary digits (bits) are used to represent the highest octal digit. When converting aoctal numberstillbinary number,three bitsare used to represent each octal digit.

The table below shows the conversion of each octal digit to its corresponding binary digits.

Number System C - Decimal, Binary, Octal and Hex (2)

For example an octal number0246is converted to the equivalent binary form as

Octal number -> 2 4 6 Binary number -> 010 100 110

For this reason0246es(010100110)2.

Likewise when converting from aSensenumber in its octal form, the binary number is divided into groups of3 digitsrespectively, starting at the far right of the given number. Each of thethree binary digitsis replaced by the appropriate oneThe octal digit.

If the leftmost group of binary digits in the number does not have three digits, the required number of zeros are added as a prefix to make three binary digits. For example, we convert aBinary number 1101100in its correspondenceoctalNumber.

Binary number -> 1 101 100 Binary number -> 001 101 100 //After leading zeros to the left end of the group Octal number -> 1 5 4

Hence the octal equivalent of the given binary number1101100es0154.

4. Hexadecimal Numbers:

The number system you useBasis-16is calledhexadecimal systemor simplyhex.A base (aka root) is the number of unique digits or symbols (including 0) used to represent a given number.

In the hexadecimal system (orBasis-16number system) a total of 16 symbols are used. Digits from0 null)A9 neun)are used to represent values ​​of0 bis 9or alphabetsA,B,C,D,mijFA,B,C,D,mi, jF) are used to represent values ​​of10 bis 15or.

In many programming languages0xused as a prefix to indicate a hexadecimal representation.

For example, in hexadecimal, the value ofnullis represented as0x0, Wo

0 = (0* sixteen0) = (0* 1)

Similar,

1 = (1* sixteen0) = (1* 1)

2 = (2* sixteen0) = (2* 1)

…..

15 =F= (15* sixteen0) = (15* 1)

Now let's represent the following numbers in hexadecimal:

decimal numbereighteen (18):

since it can only be used0 bis 9and alphabetsA ein F18 represented.

We divide 18 by 16 and write the quotient and the remainder as follows:

[quotient][remainder], that is,[1][2]

18 =0x12= (1* sixteen1) + (2* sixteen0) = (16) + (2)

hundred sixty(160).

since it can only be used0 bis 9and alphabetsA ein F160 represent.

Let's divide 160 by 16 and write the quotient and the remainder as follows:

[quotient][remainder], i.e. [10][0], [A][0] (since 10 is represented by A)

160 =0xA0 =(10* sixteen1) + (0* sixteen0) = (160) + (0)

Please note that bothcapital letterjlowercase lettersLetters can be used to represent hexadecimal values. For example,

int hex_One Hundred_and_Sixty = 0xA0; // or 0Xa0, but 0xA0 is preferred.

The highest digit in hexadecimal format is(F)sixteen. The number (F)sixteenIn binary format it is represented as(1111)2. Here,four binary digits(bits) are used to represent the highest hexadecimal digit. Inhexadecimal to binarytransformation,four bitsare used to represent eachhexadecimal digit.

The following table shows the respective conversionshexadecimal digitin its correspondencebinary numbers.

Number System C - Decimal, Binary, Octal and Hex (3)

For example hexadecimal number0x5AF6is converted to the equivalent binary form as follows:

Hexadecimal number -> 5 A F 6Binary number -> 0101 1010 1111 0110

For this reason,0x5AF6es(0101101011110110)2.

Likewise, when converting a binary number to hexadecimal, the binary number is first divided into groups of 4 digits, each beginning on the far right. Each of the four binary digits is replaced with the corresponding hexadecimal digits.

If the group on the far left ofbinary numbershas notFour Digits, the required number of zeros are added as a prefix to form a group of four binary digits.

For example, let's convert the following binary1101100Number in hexadecimal format.

Binary number -> 110 1100 Binary number -> 0110 1100 //After leading zeros in the leftmost group Hexadecimal number -> 6 C

Hence the hexadecimal equivalent of the specified binary number1101100es0x6C.

References:

Have fun learning 🙂

related posts

  1. Java binary to decimal converter
  2. Java program to convert decimal numbers to octal numbers
  3. Java octal to decimal converter
  4. Example of Python number systems
  5. Java program to convert decimal to binary numbers
  6. Java program to convert decimal numbers to hexadecimal numbers
  7. Java binary to hexadecimal converter
  8. Convert any number to a Python binary number
  9. Java program for binary addition
  10. Sample Java 7 binary literal tutorials
  11. Java program to check octal number
  12. Binary search with Java
  13. Example tutorials on PHP data types
  14. Underscores in numeric literals Java 7
  15. Program C: Addition of digits of a given number up to a single digit
Top Articles
Latest Posts
Article information

Author: Pres. Carey Rath

Last Updated: 02/07/2023

Views: 6372

Rating: 4 / 5 (41 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Pres. Carey Rath

Birthday: 1997-03-06

Address: 14955 Ledner Trail, East Rodrickfort, NE 85127-8369

Phone: +18682428114917

Job: National Technology Representative

Hobby: Sand art, Drama, Web surfing, Cycling, Brazilian jiu-jitsu, Leather crafting, Creative writing

Introduction: My name is Pres. Carey Rath, I am a faithful, funny, vast, joyous, lively, brave, glamorous person who loves writing and wants to share my knowledge and understanding with you.