473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How do i convert a decimal number to octal?

Here's the code is used but...but still something is wrong... i need help...

Expand|Select|Wrap|Line Numbers
  1. /*CONVERTING DECIMAL TO OCTAL*/
  2.         String inputDeci,octal="";
  3.         int deci,count=0, i, h;
  4.  
  5.  
  6.         inputDeci = JOptionPane.showInputDialog("Enter a decimal number ");
  7.         deci = Integer.parseInt(inputDeci);
  8.  
  9.         int [] quotient = new int [50];
  10.         int [] remainder = new int [50] ;
  11.  
  12.         quotient[0] = deci / 8;
  13.         remainder[0] = deci % 8;
  14.         octal+=""+remainder[0];
  15.  
  16.         for (i = 0; remainder[0+i] < 8 || quotient[0+i]>= 8; i++){
  17.  
  18.             quotient[i+1] = quotient[i] / 8;
  19.             remainder[i+1] = quotient[i] % 8;    
  20.             count+=1;
  21.             System.out.println(remainder[i]);
  22.  
  23.  
  24.         }
  25.         for(h=count;h<0;h--){
  26.  
  27.             octal+= ""+ remainder[h];
  28.  
  29.         }
Feb 10 '08 #1
1 4280
JosAH
11,448 Expert 8TB
Did you read about the Integer.toString(int number, int radix) method?

kind regards,

Jos
Feb 10 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Philipp H. Mohr | last post by:
Hello, I am trying to xor the byte representation of every char in a string with its predecessor. But I don't know how to convert a char into its byte representation. This is to calculate the...
13
by: Hako | last post by:
I try this command: >>> import string >>> string.atoi('78',16) 120 this is 120 not 4E. Someone can tell me how to convert a decimal number to hex number? Can print A, B, C,DEF. Thank you.
9
by: FalkoG | last post by:
Hello colleague I want to convert a floating number for example 5236.9856982 to a hexadecimal number. I'd tried several things but my problem is to convert the position after decimal point. I...
7
by: elliotng.ee | last post by:
I have a text file that contains a header 32-bit binary. For example, the text file could be: %%This is the input text %%test.txt Date: Tue Dec 26 14:03:35 2006...
9
by: Leo jay | last post by:
i'd like to implement a class template to convert binary numbers to decimal at compile time. and my test cases are: BOOST_STATIC_ASSERT((bin<1111,1111,1111,1111>::value == 65535));...
10
by: cmdolcet69 | last post by:
Public ArrList As New ArrayList Public bitvalue As Byte() Public Sub addvalues() Dim index As Integer ArrList.Add(100) ArrList.Add(200) ArrList.Add(300) ArrList.Add(400) ArrList.Add(500)
8
by: te509 | last post by:
Hi guys, does anybody know how to convert a long sequence of bits to a bit-string? I want to avoid this: '949456129574336313917039111707606368434510426593532217946399871489' I would...
23
by: neha_chhatre | last post by:
which is the best format specifier(data type) if i have to work with decimal number. also please tell me the syntax for truncating a decimal number please reply as soon as possible
1
ivelhacker
by: ivelhacker | last post by:
guys can you guide me for making a visual basic program. that will convert the octal number to decimal number.. thanks guys...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.