aspose file tools*
The moose likes Beginning Java and the fly likes Octal number conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Octal number conversion" Watch "Octal number conversion" New topic
Author

Octal number conversion

rajesh sherla
Greenhorn

Joined: Apr 04, 2010
Posts: 11
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
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
I am afraid your figures are mistaken.
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?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Octal number conversion
 
Similar Threads
Hexadecimal Question
Literal values doubt
Numerical conversions in SCJP exam?
Converting Decimal to Other bases
Converting from hex to decimal