HEX conversion 
Author Message
 HEX conversion

I know how to use HEX$ to convert decimal numbers into hexadecimal but I
would really appreciate it if anybody could explain how to convert
hexadecimal into decimal using quickbasic4.5

--
Belgarion

"No man is wise enough nor good enough to be trusted with unlimited power"



Sun, 15 Oct 2000 03:00:00 GMT  
 HEX conversion

Quote:

>I know how to use HEX$ to convert decimal numbers into hexadecimal but I
>would really appreciate it if anybody could explain how to convert
>hexadecimal into decimal using quickbasic4.5
>--
>Belgarion


&H is the prefix you need. For example: PRINT &H7FFFFFFF will show you the
longest decimal integer supported in QB.

Regards,



Sun, 15 Oct 2000 03:00:00 GMT  
 HEX conversion


Quote:
>I know how to use HEX$ to convert decimal numbers into hexadecimal but I
>would really appreciate it if anybody could explain how to convert
>hexadecimal into decimal using quickbasic4.5

<snip>

Function HexToDec$(HexNum$)
    if Len(HexNum$)<1 then exit function
    Answer#=0
    Power%=0
    For Counter%=len(HexNum$) to 1 step-1
        select case mid$(HexNum$,Counter%,1)
        case "1" to "9"
            Answer#=Answer#+(val(mid$(HexNum$,Counter%,1))*(16^Power%))
        case "A" to "F"
            Answer#=Answer#+((asc(mid$(HexNum$,Counter%,1))-55)*(16^Power%))
        end select
        Power%=Power%+1
    Next Counter%
    HexToDec$=Str$(Answer#)
End Function

The application is easy; it reads from the end of the string to the
beginning: the last digit in the string represents the multiples of 16^0
(ie, 1) in the number, the next number to the left represents the multiples
of 16^1 in the number, etc, so it merely adds them up. There's probably a
more 'elegant' way to convert A-F to 10-15 without subtracting 55 from their
ASCII value, but I don't think it's a particularly big deal.



Sun, 15 Oct 2000 03:00:00 GMT  
 HEX conversion

Quote:
>I know how to use HEX$ to convert decimal numbers
>into hexadecimal but I would really appreciate it if
>anybody could explain how to
>convert hexadecimal into decimal using quickbasic4.5

HexString$ = HEX$(Number%)
Decimal% = VAL("&H" + HexString$)

*Hope this helps!*



Sun, 15 Oct 2000 03:00:00 GMT  
 HEX conversion

Quote:

>I know how to use HEX$ to convert decimal numbers into hexadecimal but I
>would really appreciate it if anybody could explain how to convert
>hexadecimal into decimal using quickbasic4.5

'
'  **************************************************
'  *                                                *
'  *                  BASECONV.BAS                  *
'  *                                                *
'  *    Convert Number from Any Base to Any Base    *
'  *                                                *
'  *              Judson D. McClendon               *
'  *              Sun Valley Systems                *
'  *              329 37th Court N.E.               *
'  *              Birmingham, AL 35215              *
'  *                 205-853-8440                   *
'  *                                                *
'  **************************************************
'
CONST Digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
DIM NbrLong AS LONG, NbrBase1 AS STRING, NbrBase2 AS STRING
DIM Base1 AS LONG, Base2 AS LONG, P AS INTEGER, V AS INTEGER, EF AS INTEGER

DO
   INPUT "Enter base1,base2 (2-36): ", Base1, Base2
LOOP WHILE (Base1 < 2 OR Base1 > 36 OR Base2 < 2 OR Base2 > 36)

DO
   DO                         ' Input and validate NbrBase1
      EF = 0
      PRINT "Enter Number in Base"; Base1;
      INPUT "(0 to end): ", NbrBase1
      NbrBase1 = UCASE$(LTRIM$(RTRIM$(NbrBase1)))
      FOR P = 1 TO LEN(NbrBase1)
         V = INSTR(Digits, MID$(NbrBase1, P, 1))
         IF (V < 1 OR V > Base1) THEN
            PRINT "Digit "; MID$(NbrBase1, P, 1); " invalid"
            EF = 1
            EXIT FOR
         END IF
      NEXT
   LOOP WHILE (EF = 1)
   IF (NbrBase1 = "0") THEN
      END
   END IF

   NbrLong = 0                ' Convert Base1 to Long
   FOR P = 1 TO LEN(NbrBase1)
      NbrLong = NbrLong * Base1 + (INSTR(Digits, MID$(NbrBase1, P, 1)) - 1)
   NEXT

   NbrBase2 = ""              ' Convert Long to Base2
   DO
      NbrBase2 = MID$(Digits, (NbrLong MOD Base2) + 1, 1) + NbrBase2
      NbrLong = NbrLong \ Base2
   LOOP WHILE (NbrLong)
   PRINT "Number in Base"; STR$(Base2); ": "; NbrBase2
   PRINT
LOOP
END
--
Judson McClendon          This is a faithful saying and worthy of all
Sun Valley Systems        acceptance, that Christ Jesus came into the

(please remove numbers from email id to respond)



Sun, 15 Oct 2000 03:00:00 GMT  
 HEX conversion

Quote:


>>I know how to use HEX$ to convert decimal numbers into hexadecimal but I
>>would really appreciate it if anybody could explain how to convert
>>hexadecimal into decimal using quickbasic4.5
><snip>

>Function HexToDec$(HexNum$)
>    if Len(HexNum$)<1 then exit function
>    Answer#=0
>    Power%=0
>    For Counter%=len(HexNum$) to 1 step-1
>        select case mid$(HexNum$,Counter%,1)
>        case "1" to "9"
>            Answer#=Answer#+(val(mid$(HexNum$,Counter%,1))*(16^Power%))
>        case "A" to "F"

Answer#=Answer#+((asc(mid$(HexNum$,Counter%,1))-55)*(16^Power%))

Quote:
>        end select
>        Power%=Power%+1
>    Next Counter%
>    HexToDec$=Str$(Answer#)
>End Function

Or you can do this:

FUNCTION HexToDec& (HexNum$)
    Temp& = VAL("&H" + HexNum$)
    IF Temp& < 0 THEN Temp& = Temp& + 65536
    HexToDec = Temp&
END FUNCTION

Tom Lake



Sun, 15 Oct 2000 03:00:00 GMT  
 HEX conversion

What the Hell Is That

Quote:


> >I know how to use HEX$ to convert decimal numbers into hexadecimal but I
> >would really appreciate it if anybody could explain how to convert
> >hexadecimal into decimal using quickbasic4.5

> '
> '  **************************************************
> '  *                                                *
> '  *                  BASECONV.BAS                  *
> '  *                                                *
> '  *    Convert Number from Any Base to Any Base    *
> '  *                                                *
> '  *              Judson D. McClendon               *
> '  *              Sun Valley Systems                *
> '  *              329 37th Court N.E.               *
> '  *              Birmingham, AL 35215              *
> '  *                 205-853-8440                   *
> '  *                                                *
> '  **************************************************
> '
> CONST Digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
> DIM NbrLong AS LONG, NbrBase1 AS STRING, NbrBase2 AS STRING
> DIM Base1 AS LONG, Base2 AS LONG, P AS INTEGER, V AS INTEGER, EF AS INTEGER

> DO
>    INPUT "Enter base1,base2 (2-36): ", Base1, Base2
> LOOP WHILE (Base1 < 2 OR Base1 > 36 OR Base2 < 2 OR Base2 > 36)

> DO
>    DO                         ' Input and validate NbrBase1
>       EF = 0
>       PRINT "Enter Number in Base"; Base1;
>       INPUT "(0 to end): ", NbrBase1
>       NbrBase1 = UCASE$(LTRIM$(RTRIM$(NbrBase1)))
>       FOR P = 1 TO LEN(NbrBase1)
>          V = INSTR(Digits, MID$(NbrBase1, P, 1))
>          IF (V < 1 OR V > Base1) THEN
>             PRINT "Digit "; MID$(NbrBase1, P, 1); " invalid"
>             EF = 1
>             EXIT FOR
>          END IF
>       NEXT
>    LOOP WHILE (EF = 1)
>    IF (NbrBase1 = "0") THEN
>       END
>    END IF

>    NbrLong = 0                ' Convert Base1 to Long
>    FOR P = 1 TO LEN(NbrBase1)
>       NbrLong = NbrLong * Base1 + (INSTR(Digits, MID$(NbrBase1, P, 1)) - 1)
>    NEXT

>    NbrBase2 = ""              ' Convert Long to Base2
>    DO
>       NbrBase2 = MID$(Digits, (NbrLong MOD Base2) + 1, 1) + NbrBase2
>       NbrLong = NbrLong \ Base2
>    LOOP WHILE (NbrLong)
>    PRINT "Number in Base"; STR$(Base2); ": "; NbrBase2
>    PRINT
> LOOP
> END
> --
> Judson McClendon          This is a faithful saying and worthy of all
> Sun Valley Systems        acceptance, that Christ Jesus came into the

> (please remove numbers from email id to respond)



Sat, 21 Oct 2000 03:00:00 GMT  
 HEX conversion

It is exactly what it says it is.  A program to convert a number in
any base (2 through 36) into any other base (2 through 36).  The
actual conversion is about 9 lines of code at the end, the rest is
code asking which bases to convert from and to, the number to convert,
and validating them.  The numbers are stored in the form of strings.
--
Judson McClendon          This is a faithful saying and worthy of all
Sun Valley Systems        acceptance, that Christ Jesus came into the

(please remove numbers from email id to respond)

Quote:

>What the Hell Is That



>> >I know how to use HEX$ to convert decimal numbers into hexadecimal but
>> >I would really appreciate it if anybody could explain how to convert
>> >hexadecimal into decimal using quickbasic4.5

>> '
>> '  **************************************************
>> '  *                                                *
>> '  *                  BASECONV.BAS                  *
>> '  *                                                *
>> '  *    Convert Number from Any Base to Any Base    *
>> '  *                                                *
>> '  *              Judson D. McClendon               *
>> '  *              Sun Valley Systems                *
>> '  *              329 37th Court N.E.               *
>> '  *              Birmingham, AL 35215              *
>> '  *                 205-853-8440                   *
>> '  *                                                *
>> '  **************************************************
>> '
>> CONST Digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
>> DIM NbrLong AS LONG, NbrBase1 AS STRING, NbrBase2 AS STRING
>> DIM Base1 AS LONG, Base2 AS LONG, P AS INTEGER, V AS INTEGER, EF AS INTEGER

>> DO
>>    INPUT "Enter base1,base2 (2-36): ", Base1, Base2
>> LOOP WHILE (Base1 < 2 OR Base1 > 36 OR Base2 < 2 OR Base2 > 36)

>> DO
>>    DO                         ' Input and validate NbrBase1
>>       EF = 0
>>       PRINT "Enter Number in Base"; Base1;
>>       INPUT "(0 to end): ", NbrBase1
>>       NbrBase1 = UCASE$(LTRIM$(RTRIM$(NbrBase1)))
>>       FOR P = 1 TO LEN(NbrBase1)
>>          V = INSTR(Digits, MID$(NbrBase1, P, 1))
>>          IF (V < 1 OR V > Base1) THEN
>>             PRINT "Digit "; MID$(NbrBase1, P, 1); " invalid"
>>             EF = 1
>>             EXIT FOR
>>          END IF
>>       NEXT
>>    LOOP WHILE (EF = 1)
>>    IF (NbrBase1 = "0") THEN
>>       END
>>    END IF

>>    NbrLong = 0                ' Convert Base1 to Long
>>    FOR P = 1 TO LEN(NbrBase1)
>>       NbrLong = NbrLong * Base1 + (INSTR(Digits, MID$(NbrBase1, P, 1)) - 1)
>>    NEXT

>>    NbrBase2 = ""              ' Convert Long to Base2
>>    DO
>>       NbrBase2 = MID$(Digits, (NbrLong MOD Base2) + 1, 1) + NbrBase2
>>       NbrLong = NbrLong \ Base2
>>    LOOP WHILE (NbrLong)
>>    PRINT "Number in Base"; STR$(Base2); ": "; NbrBase2
>>    PRINT
>> LOOP
>> END
>> --
>> Judson McClendon          This is a faithful saying and worthy of all
>> Sun Valley Systems        acceptance, that Christ Jesus came into the

>> (please remove numbers from email id to respond)



Sun, 22 Oct 2000 03:00:00 GMT  
 HEX conversion

Quote:

> I would really appreciate it if anybody could explain how to convert
> hexadecimal into decimal using quickbasic4.5

> --
> Belgarion

> "No man is wise enough nor good enough to be trusted with unlimited power"

Try: PRINT &HA
--
Egbert Zijlema
http://www.basicguru.com/zijlema/


Fri, 27 Oct 2000 03:00:00 GMT  
 HEX conversion

Quote:


> > I would really appreciate it if anybody could explain how to convert
> > hexadecimal into decimal using quickbasic4.5

> > --
> > Belgarion

> > "No man is wise enough nor good enough to be trusted with unlimited power"

> Try: PRINT &HA

If you need to convert a variable then :

hex$="A3DC"    'or whatever

dec = val("&H" + hex$)

Quote:
> --
> Egbert Zijlema
> http://www.basicguru.com/zijlema/



Fri, 27 Oct 2000 03:00:00 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Hex conversion

2. Hex conversions - HELP

3. Hex conversion

4. Hex conversion hassles.....

5. Hex conversion hassles...

6. HEX conversion

7. HEX Conversions

8. Large number HEX conversion?

9. HELP: Integer -> Hex conversion (Overflow)

10. Hex to float conversion

11. Hex <----> Decimal conversions

12. Hex to Bin conversion

 

 
Powered by phpBB® Forum Software