PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > conversion to quadword
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
conversion to quadword

Réponse
 
LinkBack Outils de la discussion
Vieux 29/11/2007, 04h30   #1
arunmib
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut conversion to quadword

hi all,
How can I convert an Integer (int data type) and an unsigned char
data type to a quadword? I want to know the conversion mechanism....

Advance thanks for the .


  Réponse avec citation
Vieux 29/11/2007, 05h14   #2
CBFalconer
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: conversion to quadword

arunmib wrote:
>
> How can I convert an Integer (int data type) and an unsigned char
> data type to a quadword? I want to know the conversion mechanism.


What is a quadword?

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.


--
Posted via a free Usenet account from http://www.teranews.com

  Réponse avec citation
Vieux 29/11/2007, 05h15   #3
Keith Thompson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: conversion to quadword

arunmib <arunmib@gmail.com> writes:
> How can I convert an Integer (int data type) and an unsigned char
> data type to a quadword? I want to know the conversion mechanism....


What exactly is a "quadword"? C defines no such type; it doesn't even
define what a "word" is. Explain what a quadword is, and we may be
able to tell you how to convert to it.

--
Keith Thompson (The_Other_Keith) <kst-u@mib.org>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
  Réponse avec citation
Vieux 29/11/2007, 06h11   #4
cr88192
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: conversion to quadword


"arunmib" <arunmib@gmail.com> wrote in message
news:b8111616-cf83-4ddc-8e05-95b7bf9145be@d27g2000prf.googlegroups.com...
> hi all,
> How can I convert an Integer (int data type) and an unsigned char
> data type to a quadword? I want to know the conversion mechanism....
>


a word like 'quadword' will annoy the standards-heads...

as will defining such un-standardly things like 'type conversion' (too
impure and vulgar for this high and refined group, which has moved above and
beyond such primitive and carnal things as 'computers' and 'operating
systems'...).

so, in these here parts, 'long long' or 'uint64_t' are probably better
terms...

and, it suffices only to know that it does convert, not to concern outselves
with such esoteric and sinister concepts as 'sign extension' and 'zero
extension' (which may not neccissarily be the case on some or another arch
that someone can drag up from somewhere or another).

or such...


> Advance thanks for the .
>
>



  Réponse avec citation
Vieux 29/11/2007, 07h17   #5
santosh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: conversion to quadword

arunmib wrote:

> hi all,
> How can I convert an Integer (int data type) and an unsigned char
> data type to a quadword? I want to know the conversion mechanism....
>
> Advance thanks for the .


C has no type called "quadword", so it defines no conversion mechanism
for that. However your platform and implementation may implement such a
type and if so, you have to refer to their documentation to find out
the details for using it.

  Réponse avec citation
Vieux 29/11/2007, 08h54   #6
arunmib
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: conversion to quadword

On Nov 29, 12:17 pm, santosh <santosh....@gmail.com> wrote:
> arunmib wrote:
> > hi all,
> > How can I convert an Integer (int data type) and an unsigned char
> > data type to a quadword? I want to know the conversion mechanism....

>
> > Advance thanks for the .

>
> C has no type called "quadword", so it defines no conversion mechanism
> for that. However your platform and implementation may implement such a
> type and if so, you have to refer to their documentation to find out
> the details for using it.


Thanks for the information....
  Réponse avec citation
Vieux 29/11/2007, 11h22   #7
jacob navia
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: conversion to quadword

arunmib wrote:
> hi all,
> How can I convert an Integer (int data type) and an unsigned char
> data type to a quadword? I want to know the conversion mechanism....
>
> Advance thanks for the .
>
>

quadword in Intel notation is a 64 bit integer.

In 32 bit systems you can convert ints into quadwords by using
an unnecessary cast

int i;
long long a = (long long)i;

or just

long long a = i;

In intel architecture this is a sign extension of the 32 bits
into 64 bits
movsx %eax,%rax

using gcc's notation.

For unsigned chars you need an extension with ZERO extend.

In C you would write:

unsigned char c;
long long a = (long long)c;

movzxq %al,%rax

if I remember correctly.


--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
  Réponse avec citation
Vieux 29/11/2007, 11h44   #8
James Kuyper
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: conversion to quadword

arunmib wrote:
> hi all,
> How can I convert an Integer (int data type) and an unsigned char
> data type to a quadword? I want to know the conversion mechanism....
>
> Advance thanks for the .


I think that veryone has been assuming that what you really wanted to
know was the name the C quadword type. As other people have already
said, while any particular implementation of C might or might not have
an integer type which is 4 words long, the C standard does not specify
which one it is.

However, if you already know the name for the quadword type in a given
implementation of C, it may be that all you're really asking is what you
actually said: "How can I convert ... to a quadword"? If so, the answer
is that the you do it precisely the same way as any other conversion:

typedef implementation_specific_type quadword;
typedef desired_integer_type Integer;

Integer i = 42;
quadword q = (quadword)i;
unsigned char c = 'c';
q = (quadword)c;
  Réponse avec citation
Vieux 29/11/2007, 20h32   #9
Keith Thompson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: conversion to quadword

James Kuyper <jameskuyper@verizon.net> writes:
> arunmib wrote:
>> How can I convert an Integer (int data type) and an unsigned char
>> data type to a quadword? I want to know the conversion mechanism....

>
> I think that veryone has been assuming that what you really wanted to
> know was the name the C quadword type. As other people have already
> said, while any particular implementation of C might or might not have
> an integer type which is 4 words long, the C standard does not specify
> which one it is.
>
> However, if you already know the name for the quadword type in a given
> implementation of C, it may be that all you're really asking is what
> you actually said: "How can I convert ... to a quadword"? If so, the
> answer is that the you do it precisely the same way as any other
> conversion:
>
> typedef implementation_specific_type quadword;
> typedef desired_integer_type Integer;
>
> Integer i = 42;
> quadword q = (quadword)i;
> unsigned char c = 'c';
> q = (quadword)c;


Assuming that "quadword" is an integer type, the casts are
unnecessary. A value can be converted from any numeric type to any
other numeric type with a simple assignment; it will be converted
implicitly:

Integer i = 42;
quadword q = i;
unsighed char c = 'c';
q = c;

If "quadword" *isn't* a numeric type (say, if it's a structure
representing something bigger than the largest available integer
type), then there is no language-defined conversion. If the type is
provided by some library, then that library will probably provide one
or more conversion routines. If you're defining it yourself, you'll
need to define your own conversion routines.

Again, the C language doesn't define a "quadword", or even a "word".
If a "quadword" is meant to be 64 bits, then type "long long" or
"unsigned long long" is probably the right thing; these are integer
types, and can be implicitly converted to or from any other integer
types. They're guaranteed to be *at least* 64 bits; in every
implementation I've heard of they're exactly 64 bits.

If a "quadword" is 4 32-bit words, for a total of 128 bits, there most
likely isn't an integer type that big.

This is why I (and several others) asked the OP to explain to us what
a "quadword" is, and why we can't really answer his question until he
tells us.

--
Keith Thompson (The_Other_Keith) <kst-u@mib.org>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
  Réponse avec citation
Vieux 29/11/2007, 20h43   #10
jameskuyper@verizon.net
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: conversion to quadword

Keith Thompson wrote:
> James Kuyper <jameskuyper@verizon.net> writes:

....
> > However, if you already know the name for the quadword type in a given
> > implementation of C, it may be that all you're really asking is what
> > you actually said: "How can I convert ... to a quadword"? If so, the
> > answer is that the you do it precisely the same way as any other
> > conversion:
> >
> > typedef implementation_specific_type quadword;
> > typedef desired_integer_type Integer;
> >
> > Integer i = 42;
> > quadword q = (quadword)i;
> > unsigned char c = 'c';
> > q = (quadword)c;

>
> Assuming that "quadword" is an integer type, the casts are
> unnecessary. A value can be converted from any numeric type to any
> other numeric type with a simple assignment; it will be converted
> implicitly:
>
> Integer i = 42;
> quadword q = i;
> unsighed char c = 'c';
> q = c;


You're right. I was just trying to demonstrate how to explicitly make
the conversion happen by using a cast; I should have chosen an example
where the cast was actually necessary.
  Réponse avec citation
Vieux 29/11/2007, 22h57   #11
Keith Thompson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: conversion to quadword

jameskuyper@verizon.net writes:
> Keith Thompson wrote:
>> James Kuyper <jameskuyper@verizon.net> writes:

> ...
>> > However, if you already know the name for the quadword type in a given
>> > implementation of C, it may be that all you're really asking is what
>> > you actually said: "How can I convert ... to a quadword"? If so, the
>> > answer is that the you do it precisely the same way as any other
>> > conversion:
>> >
>> > typedef implementation_specific_type quadword;
>> > typedef desired_integer_type Integer;
>> >
>> > Integer i = 42;
>> > quadword q = (quadword)i;
>> > unsigned char c = 'c';
>> > q = (quadword)c;

>>
>> Assuming that "quadword" is an integer type, the casts are
>> unnecessary. A value can be converted from any numeric type to any
>> other numeric type with a simple assignment; it will be converted
>> implicitly:
>>
>> Integer i = 42;
>> quadword q = i;
>> unsighed char c = 'c';
>> q = c;

>
> You're right. I was just trying to demonstrate how to explicitly make
> the conversion happen by using a cast; I should have chosen an example
> where the cast was actually necessary.


If both types are numeric, there are very few cases where the cast is
actually necessary. You might need a cast for an argument to a
variadic function (where the compiler can't determine the expected
type), or in some cases where you want fine-grained control within an
expression. (Even in those cases, the cast isn't absolutely
necessary; you can use a temporary object instead. IMHO in such cases
a cast is cleaner; YMMV.)

All casts should be viewed with suspicion.

--
Keith Thompson (The_Other_Keith) <kst-u@mib.org>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
  Réponse avec citation
Vieux 29/11/2007, 23h08   #12
user923005
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: conversion to quadword

On Nov 28, 8:30 pm, arunmib <arun...@gmail.com> wrote:
> hi all,
> How can I convert an Integer (int data type) and an unsigned char
> data type to a quadword? I want to know the conversion mechanism....


/* Sounds like an OpenVMS programmer... */
#include <stdio.h>
int main(void)
{
long long signed_quadword;
unsigned long long unsigned_quadword;
static const int int_type = -23456;
static const unsigned char unsigned_char_type = 65;

/* Probably no surprises here */
signed_quadword = int_type;
printf("signed quadword became %lld from %d\n", signed_quadword,
int_type);
signed_quadword = unsigned_char_type;
printf("signed quadword became %lld from '%c'=%u\n",
signed_quadword, unsigned_char_type, (unsigned) unsigned_char_type);
unsigned_quadword = unsigned_char_type;
printf("unsigned quadword became %llu from '%c'=%u\n",
unsigned_quadword, unsigned_char_type, (unsigned) unsigned_char_type);

/* This one may provide surprises: */
unsigned_quadword = (unsigned long long) int_type;
printf("unsigned quadword became %llu from %d\n",
unsigned_quadword, int_type);

return 0;
}
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h22.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,25848 seconds with 20 queries