Thread: Help needed related to debugging a code

  1. #1
    Registered User
    Join Date
    May 2022
    Posts
    4

    Help needed related to debugging a code

    Hi there, I hope you will be doing great.

    I am trying to study and understand a code that is in C language and want to implement it in MATLAB environment. However, the problem is I am not familiar with C language.

    The issue currently I am facing is in the debugging. I don't know whether the following section is storing data in binary format or in decimal format in variables?

    I am using VS code on windows 10

    Help needed related to debugging a code-sub-png

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    It depends what you mean by "decimal format".

    C only knows about binary at the machine level.

    The whole decimal/binary thing is purely down to presentation, such as when you try and print a variable in the debugger, or using printf.
    Code:
    int x = 128;
    int y = 0x80;
    if ( x == y ) {
      // it's true!
    }
    printf("%d %d\n", x, y);  // print both in decimal
    printf("%x %x\n", x, y);  // print both in hex
    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
    Registered User
    Join Date
    May 2022
    Posts
    4
    Ok so it means the above elements are stored in decimal format in the variable?

    When I try to debug the code using vscode I can only see their decimal values...

  4. #4
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Quote Originally Posted by C_shot1 View Post
    Ok so it means the above elements are stored in decimal format in the variable?
    "C only knows about binary at the machine level" means: There is no "decimal format"!

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Quote Originally Posted by C_shot1 View Post
    Ok so it means the above elements are stored in decimal format in the variable?

    When I try to debug the code using vscode I can only see their decimal values...
    Decimal is just how the debugger chooses to show you the numbers.

    There are options in the debugger to allow you to show values in hexadecimal.
    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.

  6. #6
    Registered User
    Join Date
    May 2022
    Posts
    4
    Quote Originally Posted by Salem View Post
    Decimal is just how the debugger chooses to show you the numbers.

    There are options in the debugger to allow you to show values in hexadecimal.
    Thank you is it possible in the Visual studio code?

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    SureHelp needed related to debugging a code-vs-debug-png
    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: 3
    Last Post: 12-07-2015, 09:01 PM
  2. Urgent homework / debugging help needed!!!
    By jollykiddo in forum C Programming
    Replies: 2
    Last Post: 12-16-2011, 03:02 AM
  3. Replies: 1
    Last Post: 03-10-2010, 11:28 AM
  4. help needed in organising a debugging contest
    By shrijeetp in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 01-22-2006, 07:45 AM
  5. Replies: 2
    Last Post: 03-21-2004, 08:21 PM

Tags for this Thread