Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Ok how do I do this |
| Date | 2015-12-12 18:06 -0800 |
| Organization | None to speak of |
| Message-ID | <ln4mfngl0o.fsf@kst-u.example.com> (permalink) |
| References | <n4i624$det$1@dont-email.me> <lnbn9vgp9v.fsf@kst-u.example.com> <n4iipp$p6o$1@dont-email.me> |
"Bill Cunningham" <nospam@nspam.invalid> writes:
> "Keith Thompson" <kst-u@mib.org> wrote in message
> news:lnbn9vgp9v.fsf@kst-u.example.com...
>> "Bill Cunningham" <nospam@nspam.invalid> writes:
>>> I had an unsigned int a[512] similar say to sector size of some
>>> filesystems. My thinking was to use while and for anyway I ways
>>> thinking two loops would be needed one inside the other perhaps. To
>>> fill the array a[512] with the unsigned int value of 'F' which I
>>> believe is 70 in decimal.
[...]
>>> #include <stdio.h>
>>> #include <string.h>
>>>
>>> int main()
>>> {
>>> unsigned int a[512];
>>> unsigned int *pu;
>>> pu = memset(a, 'F', 512);
>>> printf("%u\n", pu);
>>> }
[...]
>> To set each byte of the array to 'F' (thereby setting each element to
>> 0x46464646):
>>
>> memset(a, 'F', sizeof a);
>>
>> To set each element of the array to 'F' (0x00000046):
>>
>> for (int i = 0; i < sizeof a / sizeof a[0]; i ++) {
>> a[i] = 'F';
>> }
[...]
>
> The 0x4646 would be ok. But here's where I'm getting the F.
The two options I presented were 0x46 and 0x46464646. Why are you
bringing up 0x4646?
> 0xFF == 11111111
>
> If a series of bytes or bit are set or "on" the hex value will be 0xFF or as
> in the olden days 0FFh.
Impressive. You probably had more misconceptions than lines of
code in your example, and yet there was another that you managed
to hide away.
The letter F in the character constant 'F' and the letter F in the
hexadecimal constant 0xFF are unrelated. In the latter, F is a digit
representing the value 15; 0xFF means exactly the same thing as 255.
If you really want help doing something, you need to explain what
the actual goal is. Filling an array of unsigned int with the
character 'F', as I said, doesn't make much sense. Filling it with
0xFF probably makes a little more sense, but there was no way anyone
could have figured out that when you wrote 'F' your really mean 0xFF.
I still have no clue why you want to do this, but you can do it
by replacing each occurrence of the character constant 'F' in my
suggested solutions above by the hexadecimal integer constant 0xFF.
If you're trying to initialize each byte to 0xFF, but "0x4646
would be ok", then I must conclude that you have no more of a clue
about what you're trying to accomplish than I have. If setting
the array elements to 0xFF, 0xFFFFFFFF, or to 0x4646 would all be
acceptable, would turning off your computer and walking away be
equally acceptable?
What are you trying to do, and why? Don't even think about writing
a line of code until you've decided that.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Ok how do I do this "Bill Cunningham" <nospam@nspam.invalid> - 2015-12-12 17:13 -0500
Re: Ok how do I do this Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-12-12 17:27 -0500
Re: Ok how do I do this "Bill Cunningham" <nospam@nspam.invalid> - 2015-12-12 17:30 -0500
Re: Ok how do I do this Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-12-12 14:40 -0800
Re: Ok how do I do this Jerry Stuckle <jstucklex@attglobal.net> - 2015-12-12 17:55 -0500
Re: Ok how do I do this "Bill Cunningham" <nospam@nspam.invalid> - 2015-12-12 18:01 -0500
Re: Ok how do I do this "Osmium" <r124c4u102@comcast.net> - 2015-12-12 17:20 -0600
Re: Ok how do I do this Keith Thompson <kst-u@mib.org> - 2015-12-12 16:34 -0800
Re: Ok how do I do this "Bill Cunningham" <nospam@nspam.invalid> - 2015-12-12 20:51 -0500
Re: Ok how do I do this "Osmium" <r124c4u102@comcast.net> - 2015-12-12 20:00 -0600
Re: Ok how do I do this "Osmium" <r124c4u102@comcast.net> - 2015-12-12 20:01 -0600
Re: Ok how do I do this Keith Thompson <kst-u@mib.org> - 2015-12-12 18:06 -0800
Re: Ok how do I do this "Bill Cunningham" <nospam@nspam.invalid> - 2015-12-12 21:21 -0500
Re: Ok how do I do this Keith Thompson <kst-u@mib.org> - 2015-12-12 18:41 -0800
Re: Ok how do I do this "Bill Cunningham" <nospam@nspam.invalid> - 2015-12-12 21:12 -0500
Re: Ok how do I do this Keith Thompson <kst-u@mib.org> - 2015-12-12 18:28 -0800
Re: Ok how do I do this Ian Collins <ian-news@hotmail.com> - 2015-12-13 13:56 +1300
Re: Ok how do I do this Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-12-13 15:42 +0000
Re: Ok how do I do this "Bill Cunningham" <nospam@nspam.invalid> - 2015-12-13 11:09 -0500
Re: Ok how do I do this "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-12-13 12:35 -0800
Re: Ok how do I do this "Bill Cunningham" <nospam@nspam.invalid> - 2015-12-14 12:59 -0500
Re: Ok how do I do this asetofsymbols@gmail.com - 2015-12-13 10:26 -0800
csiph-web