# Octal number conversion

rajesh sherla

Greenhorn

Posts: 11

posted 4 years ago

Hi All,

For integer if i want to specify hexadecimal number then max length can be 15 digits only.

And i want to specify Octal number then max length can be 21 digits only.

Can anybody tell me how internally java convert input number

option1) hexadecimal -to- binary

option2) octal -to- hexidecimal -to- binary

Because for integer we can have upto 16 bits, so hexadecimal 15 digits is valid because 2^4=16 i.e 4 bit is used to represent one value.

For Octal we can have upto 21 digits, but with 3 bits we can represent 1 value. Is Octal is converted to hexadecimal and then to binary ???

Can anybody tell me in which way number system conversion is performed in java.

Thanks in advance

For integer if i want to specify hexadecimal number then max length can be 15 digits only.

And i want to specify Octal number then max length can be 21 digits only.

Can anybody tell me how internally java convert input number

option1) hexadecimal -to- binary

option2) octal -to- hexidecimal -to- binary

Because for integer we can have upto 16 bits, so hexadecimal 15 digits is valid because 2^4=16 i.e 4 bit is used to represent one value.

For Octal we can have upto 21 digits, but with 3 bits we can represent 1 value. Is Octal is converted to hexadecimal and then to binary ???

Can anybody tell me in which way number system conversion is performed in java.

Thanks in advance

Campbell Ritchie

Sheriff

Posts: 49793

69

posted 4 years ago

I am afraid your figures are mistaken.

An

For a

The number conversion is not fixed, and can vary from one version of the JVM to another. There are standard techniques, particularly since the value used bo octal are all in the range 000...111 per digit. There is no need to convert octal and hexadecimal to each other; they are both easy to convert to binary.

Do you still use octal?

An

`int`is 32 bits, that is 8 hexadecimal digits, or 11 octal digits, the leftmost one not being > 3, not including the leading 0/0x.For a

`long`that is 16 hexadecimal digits or 22 octal digits, the leftmost one being 0 or 1, not including the leading 0/0x.The number conversion is not fixed, and can vary from one version of the JVM to another. There are standard techniques, particularly since the value used bo octal are all in the range 000...111 per digit. There is no need to convert octal and hexadecimal to each other; they are both easy to convert to binary.

Do you still use octal?

posted 4 years ago

int does not have 16 bits but 32.

In hexadecimal form, the 32 bits are split into blocks of 4 bits each. You get 8 blocks, each of which can be represented with one single char (0-9 or A-F). Therefore, you have a maximum of 8 characters (0 to FFFFFFFF). If you add the leading 0x that's 3 to 10 characters.

In octal form, the 32 bits are split into blocks of 3 bits each. You get 11 blocks, each of which can be represented with one single char (0-7). Therefore, you have a maximum of 11 characters (0 to 37777777777). If you add the leading 0 that's 1 to 12 characters.

In hexadecimal form, the 32 bits are split into blocks of 4 bits each. You get 8 blocks, each of which can be represented with one single char (0-9 or A-F). Therefore, you have a maximum of 8 characters (0 to FFFFFFFF). If you add the leading 0x that's 3 to 10 characters.

In octal form, the 32 bits are split into blocks of 3 bits each. You get 11 blocks, each of which can be represented with one single char (0-7). Therefore, you have a maximum of 11 characters (0 to 37777777777). If you add the leading 0 that's 1 to 12 characters.

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6

How To Ask Questions How To Answer Questions