473,395 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Showing numbers algorithm

Hi all,
I am making an emulator and I want to show all its memory contents. But i
don't want to say :
memory address 1 : xxxx
memory address 2 : xxxx

but something like that :
memory address 0001 : xxxx
memory address 0002 : xxxx

I hope you understand what I mean. I tried doing it with strings but I know
there is a simplier way ...
Thanks is advance
Nov 14 '05 #1
3 1244
"Darksun4" <da*******@yahoo.gr> wrote:
don't want to say :
memory address 1 : xxxx
memory address 2 : xxxx

but something like that :
memory address 0001 : xxxx
memory address 0002 : xxxx

I hope you understand what I mean. I tried doing it with strings but I know
there is a simplier way ...


Yes, there is. Use a precision specifier in your printf() format:

printf("memory address %.4u: %.2x\n", address, memory[address]);

This presumes both address and memory are unsigned ints, of course.

Richard
Nov 14 '05 #2
Richard Bos <rl*@hoekstra-uitgeverij.nl> wrote:
"Darksun4" <da*******@yahoo.gr> wrote:
don't want to say :
memory address 1 : xxxx
memory address 2 : xxxx

but something like that :
memory address 0001 : xxxx
memory address 0002 : xxxx

I hope you understand what I mean. I tried doing it with strings but I know
there is a simplier way ...

Yes, there is. Use a precision specifier in your printf() format: printf("memory address %.4u: %.2x\n", address, memory[address]); This presumes both address and memory are unsigned ints, of course.


Wouldn't the OP better off with a field width (and a preceeding '0'
to fill with zeros instead of spaces) like

printf("memory address %04u : %02x\n", address, memory[address]);

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Nov 14 '05 #3

<Je***********@physik.fu-berlin.de> wrote in message
news:2l************@uni-berlin.de...
Richard Bos <rl*@hoekstra-uitgeverij.nl> wrote:
"Darksun4" <da*******@yahoo.gr> wrote:

don't want to say :
memory address 1 : xxxx
memory address 2 : xxxx

but something like that :
memory address 0001 : xxxx
memory address 0002 : xxxx

I hope you understand what I mean. I tried doing it with strings but I know there is a simplier way ...

Yes, there is. Use a precision specifier in your printf() format:

printf("memory address %.4u: %.2x\n", address, memory[address]);

This presumes both address and memory are unsigned ints, of course.


Wouldn't the OP better off with a field width (and a preceeding '0'
to fill with zeros instead of spaces) like

printf("memory address %04u : %02x\n", address, memory[address]);

Thanks a lot guys :) That's what I wanted ( I should have man printf first
:)
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: dleecurt | last post by:
Hello, I have a small problem, I am trying to write a program that will calculate the Fibonacci number series, and I have the code complete with one problem. I used a long in to store the numbers,...
5
by: lallous | last post by:
Hello, This code works fine when 'size' is less than 32768 however when size is bigger this function never returns. Can't find out why?! If I break into the code I can see that 'i' is 32768.......
2
by: Peter R | last post by:
Hi, Probably this question was asked before, but what is the algorithm to generate all combinations based on N numbers? For example, for 3 elements = {1,2,3}, I'd like to generate a list of...
5
by: Robert Bralic | last post by:
Dear, I weated a simple program, he is compiled with gcc, and generates prim numbers, with fastes method that I find.He is based on divide with generated prim numbers... At end he gives time...
16
by: a | last post by:
We are writing an app that assigns people to teams based on their curent score. Teams are 8 people, there are 2 teams. (i would like it to be flexible, but this is a start). I need an algorithm...
12
by: Jim Michaels | last post by:
I need to generate 2 random numbers in rapid sequence from either PHP or mysql. I have not been able to do either. I get the same number back several times from PHP's mt_rand() and from mysql's...
60
by: rhle.freak | last post by:
Here is my code to generate prime numbers.It works absolutely fine when the range is *not very large*. However on initializing i with a large integer it produces erroneous results (some numbers...
9
by: Chelong | last post by:
Hi All I am using the srand function generate random numbers.Here is the problem. for example: #include<iostream> #include <time.h> int main() {
3
by: emalcolm_FLA | last post by:
Hello and Thanks in advance for any help. I have been tasked with rewriting a christmas assistance database using Access 2003. The old system used pre-assigned case numbers to identify...
11
by: zj262144 | last post by:
Hi, I'm a C beginner. I want to write a C. The pseudocodes are like this: User enters some numbers (use -1 to end) The compiler find and delete the maximum and minimum numbers Then average...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.