Thread: Spliting the bytes

  1. #1
    Unregistered
    Guest

    Question Spliting the bytes

    I have a counter that counts number of bytes in one line.
    When that counter reaches 16 bytes line is printed.
    I need to print the 16 bit address of the first byte printed(in HEX).
    eg.
    first line 0000
    second 0010
    third 0020
    0030 etc.
    All i have is counter that has 16 in it. And I need 0010.
    Next time when it reaches 32 it must be 0020.
    Line 17 will be 0100. etc
    ( I already have a function that will convert to ASCII Hex)

    Any help is welcomed.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Use the printf format modifiers. Here's an example:
    Code:
    #include <stdio.h>
    
    int main(void)
    {
    	int i;
    	
    	for (i = 0; i < 512; i += 16)
    	{
    		printf ("i is %04x\n", i);
    	}
    	
    	return 0;
    }
    
    /* Program output 
    i is 0010
    i is 0020
    i is 0030
    i is 0040
    i is 0050
    i is 0060
    i is 0070
    i is 0080
    i is 0090
    i is 00a0
    i is 00b0
    ....
    */
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reverse Engineering on a Download file
    By c_geek in forum C Programming
    Replies: 1
    Last Post: 03-22-2008, 03:15 PM
  2. Page File counter and Private Bytes Counter
    By George2 in forum Tech Board
    Replies: 0
    Last Post: 01-31-2008, 03:17 AM
  3. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  4. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  5. socket question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-19-2002, 01:54 PM