Hy,
I want to use an array tu transform from base 64 to decimal.
The problem is the function always returns 0... :(
The reason is that $digit64[$str[$i++]] is always 0 but i don't know why.
$str[$i++] is 'B' just as it should but $digit64[$str[$i++]] is 0;
if i try with $digit64['B'] the result is 11 (11 is the corect result);
Please help.
Thx in advance -
$digit64 = array('0'=>0, '1'=>1, '2'=>2, '3'=>3, '4'=>4, '5'=>5, '6'=>6, '7'=>7, '8'=>8, '9'=>9, 'A'=>10, 'B'=>11, 'C'=>12, 'D'=>13, 'E'=>14, 'F'=>15, 'G'=>16, 'H'=>17, 'I'=>18, 'J'=>19, 'K'=>20, 'L'=>21, 'M'=>22, 'N'=>23, 'O'=>24, 'P'=>25, 'Q'=>26, 'R'=>27, 'S'=>28, 'T'=>29, 'U'=>30, 'V'=>31, 'W'=>32, 'X'=>33, 'Y'=>34, 'Z'=>35, 'a'=>36, 'b'=>37, 'c'=>38, 'd'=>39, 'e'=>40, 'f'=>41, 'g'=>42, 'h'=>43, 'i'=>44, 'j'=>45, 'k'=>46, 'l'=>47, 'm'=>48, 'n'=>49, 'o'=>50, 'p'=>51, 'q'=>52, 'r'=>53, 's'=>54, 't'=>55, 'u'=>56, 'v'=>57, 'w'=>58, 'x'=>59, 'y'=>60, 'z'=>61, 'z'=>61, '+'=>62, '-'=>63);
-
-
function base10($nr){
-
$i = 0;
-
$str = $nr;
-
$nr10 = 0;
-
$n = strlen($str);
-
while($i<$n){
-
$nr10 = $nr10*64 + $digit64[$str[$i++]];
-
}
-
return $nr10;
-
}
-
-
echo base10('B');
-
2 1106 Atli 5,058
Expert 4TB
Hi.
That would be because your array, $digit64, is defined outside the scope of the function where it is used. As a result, the array is undefined inside the function, causing it to return a NULL value when used, which is converted into 0 when you use it in your calculations.
Try defining the array inside the function or import it using the global keyword.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: point |
last post by:
Hi there..
I have the folowing array
=> property = hexonet
=> property = 2003-12-01 18:46:20.0
=> property = hexonet
=> property = 2003-12-02 02:59:15.0
=> property = hexonet
=>...
|
by: Antti Nummiaho |
last post by:
Consider the following javascript:
var temp = new Array(new Array(0))
document.writeln(temp)
temp = new Array(new Array(0,1))
document.writeln(temp)
One would assume that it would print "0...
|
by: ritchie |
last post by:
Hi all,
I am new to this group and I have question that you may be able to
help me with.
I am trying to learn C but am currently stuck on this.
First of all, I have a function for each sort...
|
by: inkexit |
last post by:
I need help figuring out what is wrong with my code. I posted here a
few weeks ago with some code about creating self similar melodies in
music. The coding style I'm being taught is apparently a...
|
by: sandy |
last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory',
within my class Directory (Can you already smell disaster?)
Each Directory can have subdirectories so I thought to put these...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |