Thread: integer to hexadecimal

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    37

    integer to hexadecimal

    Hi,

    I am programming a PIC controller and need to be able to do hexadecimal manipulation.

    Here is my code in MikroC

    [code]
    int percentage percent_digit1, percent_digit2, percent_digit3;
    percentage = 28;
    percent_digit3 = percentage % 10;
    percent_digit2 = percentage / 10;
    if((percent_digit2 == 0) && (perccent_digit3 == 0) {
    percent_digit1 == 1;
    else
    percent_digit1 == 0;
    [code]

    In my MikroC code I can do the following

    Code:
    char percent_digit3[1];
    percent_digit3[0] = 0x08; //prints the ascii character corresponding to 0x08
    which stores 0x08 as one byte.

    I need to be able to take an integer and convert it to a hexadecimal number and store the hex in one byte of memory.

    So if I take 28% I need to be able to convert and store 2 as a hex in one char variable lets say hex_1[1] and convert and store 8 as a hex in one char variable lets say hex_2[1]

    Does anyone know how to do this?

    Any help would be greatly appreciated

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4
    you need convert every digit to hex? I think it's no need converter! the digits always range 0 until 9, from dec to hex it's no need converter! you just need parsing every digit.
    note:
    in your code i see
    Code:
    char percent_digit3[1];
    I think it's not array because only a member like as variable
    explain again your code !

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  3. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  4. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 10:53 AM
  5. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM