Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

hexa convertion

can any one please help me to write hexa convertion program without using (%x) control string function.

Comments

  • stoberstober Posts: 9,765 ✭✭✭
    : can any one please help me to write hexa convertion program without using (%x) control string function.
    :

    hex digits are in the range '0' to '9' and 'A' to 'F', where 'A' = 10, 'B' = 11, etc. So if you have a hex string, just convert each digit to its decimal binary value. A digit can be converted to its binary value like this:
    [code]
    int n;
    char digit = '0';
    // just subtrace '0' from any digit that is in
    // the range '0' to '9'.
    n = digit - '0';
    //
    // convert 'A' to decimal binary value
    char digit = 'A';
    n = (digit - 'A') + 10;
    [/code]

    Post some code if you have other problems.
Sign In or Register to comment.