• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

java help

amdskip

Lifer
I'm trying to convert a decimal value into the appropriate base. I posted just some of my code here. Base is a char global variable and it holds the value of b, o, h, etc. I'm getting the error message "cannot resolve symbol variable base".

static String decimalToBase(int d)
{
if (base == 'b')
{
String b = "";
while(d > 0)
{
b = "" + (d%2) + b;
d /= 2;
}
return b + 'b';
}
 
Woohoo, number base conversion in perl. I realize this doesn't help you, but I felt like posting it 😛:

#!/usr/bin/perl
print "Start Base: ";
$base = <>;
print "End Base: ";
$ebase = int <>;
print "Number: ";
$bin = <>;
chomp $bin;
@bin = split //, $bin;
foreach $bit(@bin){
if($bit !~ m/\d/){push @ret1, (ord uc $bit) - 55}
else{push @ret1, $bit}
}
$dec = shift @ret1;
foreach $bit(@ret1){$dec = $dec * $base + $bit}
while($dec > 0){
push @result, $dec % $ebase;
$dec = int $dec / $ebase;
}
foreach $bit(@result){
if($bit > 9){unshift @ret2, chr $bit + 55}
else{unshift @ret2, $bit}
}
print "Base $ebase: ", @ret2;
 
Char base is declared in main

char base;
base = returnBase(num1, num2, arg1, arg2);
I can put a System.out.println in main for base and it works, hmm, I'm a newbie with this stuff.
 
I took one semester of java and I remember pretty much nothing. In other words, I can't help you in the least here.
 
Originally posted by: ThisIsMatt
It's declared IN main, or as a global?
I think it was just in main so I had to add it to the method. Now I just have to get these calculations set up correctly.

 
Back
Top