Data Type In Python Part-2

For professionals and Freshers



In int data type we can specify a values in many forms :

1.Decimal Form
2.Binary Form
3.Octal Form
4.Hexadecimal Form


Decimal Number means having base 10, it allows digit from 0 to 9.
Binary Number means having base 2, it allows only two digit 0 and 1.
Octal Number means having base 8, it allows digit from  0 to 8
Hexadecimal number having base 16 , it allows digit from 0 to 9 and alphabet from a to f or( A to F)


Example :

Decimal : x=1111;

Binary   :  x=0b1111  = In this example before number you append  "0b" (zero and b) prefix hence python consider it as Binary number.
hence if we print x then we will get output 15

Octal:  x=0O1111 = In this example before number you append  "0O" (0 and O )prefix hence python consider it as Octal number.
hence if we print x then we will get output 585

Octal:  x=0X1111 = In this example before number you append  "0X" (0 and x )prefix hence python consider it as Hexadecimal number.
hence if we print x then we will get output 4369



Python provides some inbuilt function for number conversion / base conversion

1.bin()   - a. Converts decimal to binary
                b. Converts bool to binary
                c. Octal to Binary
                d. Hexadecimal to binary

Example : bin(15) - 0b1111
                 bin(True) - 0b1
                 bin(0o1111) - ob101001001
                 bin(0X1111)- ob1000100010001

Note1 - bin() function cant convert float complex and string to binary

Note2- For float values binary ,octal,and Hexadecimal not allowed.





Comments

Popular posts from this blog

Filter In Javafx

Kotlin with StandAlone Complier