Thread: Allowed number bases for uint8_t variables

  1. #1
    Registered User
    Join Date
    Nov 2020
    Posts
    1

    Question Allowed number bases for uint8_t variables

    I know this is a simple question, but I'm having trouble finding the answer. Example function:
    I2C_Mode I2C_Master_ReadReg(uint8_t dev_addr, uint8_t reg_addr, uint8_t count)
    Because the parameters are mainly register addresses, is it possible to give the parameters as hexidecimal or binary? Or does uint8_t only accept decimal values? Will putting 0x68 or 1101000 instead of 104 cause an error during execution or be syntactically incorrect?

    I can give more details if needed.

    Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Variables don't care about bases. It's all binary to the machine.

    It makes no difference if you say
    var = 104;
    var = 0x68;

    But your average desktop oriented compiler doesn't understand binary constants, but they are common for compilers targeting embedded / small devices.
    So you might also be able to say
    var = 0b1101000;
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 07-02-2019, 02:32 PM
  2. Replies: 2
    Last Post: 03-11-2015, 05:20 AM
  3. Replies: 1
    Last Post: 04-23-2011, 08:40 PM
  4. decimal to number if digits in different bases
    By jorgejags in forum C Programming
    Replies: 21
    Last Post: 09-24-2008, 12:55 PM
  5. number of variables
    By Saimadhav in forum C++ Programming
    Replies: 1
    Last Post: 08-01-2008, 06:06 AM

Tags for this Thread