In my project, I have scenario where i need to convert the hexadecimal value to integer value,But there is no standard function to convert the value. After searching in SCN, finally got a suggestion from one of SCN friend's(Rajan) then i could able to achieve the requirement by creating an optimized custom function.
$LV_VIN = upper($P_VIN) ;
$LV_RESULT = DECODE(length(LTRIM(RTRIM($LV_VIN, ' '),' ')) > 0 , 0 , -1 );
$LEN = length(LTRIM(RTRIM($LV_VIN, ' '),' '));
#PRINT($LEN );
IF ($LV_RESULT =0)
begin
$LV_VINMod = $LV_VIN ;
$LV_Pos =0;
$LV_Value =0;
WHILE ($LV_Pos <= $LEN )
BEGIN
$lv_char = substr($LV_VINMod ,$LEN-$LV_Pos , 1 );
#print('position'||$lv_char);
$LV_Value = $LV_Value + (cast(decode($lv_char = 'A' ,10,
$lv_char = 'B' ,11,
$lv_char = 'C' ,12,
$lv_char = 'D' ,13,
$lv_char = 'E' ,14,
$lv_char = 'F' ,15, $lv_char),'INT') * power(16,cast($LV_Pos,'INT')));
$LV_Pos = $LV_Pos + 1;
END
END
PRINT ($LV_Value);
RETURN $LV_Value ;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
2 | |
2 |