Thread: HEX value to variable

  1. #1
    Registered User
    Join Date
    Sep 2007
    Location
    Md
    Posts
    7

    HEX value to variable

    I am trying to use a variable that will have a HEX value. I have tried using char s[4] but this doesn't work in the command outportb(address,address).
    Any idea what I could use?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,663
    addr = 0x40a;
    For example.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    Code:
    char s[4];
    declare 4 separate variables who'll be able to contain hexadecimal numbers from 0x00 to 0xFF (in most implementation).

  4. #4
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    char s[4];

    declare 4 separate variables who'll be able to contain hexadecimal numbers from 0x00 to 0xFF (in most implementation).
    Why would you need to declare 4 seperate variables? Hexadecimal is only a different representation. The number held would still be the same. IE:
    Code:
    #include <stdio.h>
    
    int main()
    {
        char a = 0x41;
        printf("Hex: %x\n", a);
        printf("Decimal: %d\n", a);
        printf("ASCII: %c\n", a);
        getchar();
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 12:07 PM
  3. static class variable vs. global variable
    By nadamson6 in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2005, 03:31 PM
  4. Is binary HEX?
    By Budgiekarl in forum Tech Board
    Replies: 11
    Last Post: 11-23-2003, 09:02 AM
  5. Looking to extract a hex value out of a buffer
    By MMC in forum C Programming
    Replies: 9
    Last Post: 04-12-2002, 01:51 PM