c中按位或运算符的结果
Result of bitwise OR operator in c
我有一个关于按位或的问题 |运算符从 c 到 rust。
我有很多定义可以从 c 转换为 rust,但我不确定标志 SEFLG_ASTROMETRIC。
#define SEFLG_JPLEPH 1 /* use JPL ephemeris */
#define SEFLG_SWIEPH 2 /* use SWISSEPH ephemeris */
#define SEFLG_MOSEPH 4 /* use Moshier ephemeris */
#define SEFLG_HELCTR 8 /* heliocentric position */
#define SEFLG_TRUEPOS 16 /* true/geometric position, not apparent position */
#define SEFLG_J2000 32 /* no precession, i.e. give J2000 equinox */
#define SEFLG_NONUT 64 /* no nutation, i.e. mean equinox of date */
#define SEFLG_SPEED3 128 /* speed from 3 positions (do not use it,
* SEFLG_SPEED is faster and more precise.) */
#define SEFLG_SPEED 256 /* high precision speed */
#define SEFLG_NOGDEFL 512 /* turn off gravitational deflection */
#define SEFLG_NOABERR 1024 /* turn off 'annual' aberration of light */
#define SEFLG_ASTROMETRIC (SEFLG_NOABERR|SEFLG_NOGDEFL) /* astrometric position,
* i.e. with light-time, but without aberration and
* light deflection */
#define SEFLG_EQUATORIAL (2*1024) /* equatorial positions are wanted */
#define SEFLG_XYZ (4*1024) /* cartesian, not polar, coordinates */
#define SEFLG_RADIANS (8*1024) /* coordinates in radians, not degrees */
#define SEFLG_BARYCTR (16*1024) /* barycentric position */
#define SEFLG_TOPOCTR (32*1024) /* topocentric position */
#define SEFLG_ORBEL_AA SEFLG_TOPOCTR /* used for Astronomical Almanac mode in
* calculation of Kepler elipses */
#define SEFLG_SIDEREAL (64*1024) /* sidereal position */
#define SEFLG_ICRS (128*1024) /* ICRS (DE406 reference frame) */
#define SEFLG_DPSIDEPS_1980 (256*1024) /* reproduce JPL Horizons
* 1962 - today to 0.002 arcsec. */
#define SEFLG_JPLHOR SEFLG_DPSIDEPS_1980
#define SEFLG_JPLHOR_APPROX (512*1024) /* approximate JPL Horizons 1962 - today */
1024 | 512
我用 mac 1024 OR 512 的计算器试了一下,结果是 1536。这个结果正确吗?
是的,它是正确的。
512 =01000000000
1024=10000000000
1536=11000000000
OR-计算:
10000000000
|01000000000
=11000000000
一句话-是的。请注意,1024
和 512
在相同位置没有“1”位,因此对它们进行按位或运算的结果与将它们相加的结果相同。
是的,结果是正确的:事实上,OR-ing 1024 和 512 产生的数字与将它们相加得到的数字相同。
这是一个方便的 "shortcut" 对两个幂进行 OR 运算:因为它们的数字永远不会占据相同的位置,加法与 "OR" 相同。
当非零位置不重叠时,这里使用的原理与在除单个位置以外的所有位置添加零的小数相同:添加,比方说,6000+900+30+7 与将各个数字写到 6937 中,因为位值不会相互影响。 OR-ing 二进制中两个不同的幂等同于在被 OR-ed 的数字指定的位置写下所有 1。
请注意,表达式 (SEFLG_NOABERR|SEFLG_NOGDEFL)
是在编译时计算的,因此将其替换为 1536 不会产生任何 运行 时间改进。
我有一个关于按位或的问题 |运算符从 c 到 rust。
我有很多定义可以从 c 转换为 rust,但我不确定标志 SEFLG_ASTROMETRIC。
#define SEFLG_JPLEPH 1 /* use JPL ephemeris */
#define SEFLG_SWIEPH 2 /* use SWISSEPH ephemeris */
#define SEFLG_MOSEPH 4 /* use Moshier ephemeris */
#define SEFLG_HELCTR 8 /* heliocentric position */
#define SEFLG_TRUEPOS 16 /* true/geometric position, not apparent position */
#define SEFLG_J2000 32 /* no precession, i.e. give J2000 equinox */
#define SEFLG_NONUT 64 /* no nutation, i.e. mean equinox of date */
#define SEFLG_SPEED3 128 /* speed from 3 positions (do not use it,
* SEFLG_SPEED is faster and more precise.) */
#define SEFLG_SPEED 256 /* high precision speed */
#define SEFLG_NOGDEFL 512 /* turn off gravitational deflection */
#define SEFLG_NOABERR 1024 /* turn off 'annual' aberration of light */
#define SEFLG_ASTROMETRIC (SEFLG_NOABERR|SEFLG_NOGDEFL) /* astrometric position,
* i.e. with light-time, but without aberration and
* light deflection */
#define SEFLG_EQUATORIAL (2*1024) /* equatorial positions are wanted */
#define SEFLG_XYZ (4*1024) /* cartesian, not polar, coordinates */
#define SEFLG_RADIANS (8*1024) /* coordinates in radians, not degrees */
#define SEFLG_BARYCTR (16*1024) /* barycentric position */
#define SEFLG_TOPOCTR (32*1024) /* topocentric position */
#define SEFLG_ORBEL_AA SEFLG_TOPOCTR /* used for Astronomical Almanac mode in
* calculation of Kepler elipses */
#define SEFLG_SIDEREAL (64*1024) /* sidereal position */
#define SEFLG_ICRS (128*1024) /* ICRS (DE406 reference frame) */
#define SEFLG_DPSIDEPS_1980 (256*1024) /* reproduce JPL Horizons
* 1962 - today to 0.002 arcsec. */
#define SEFLG_JPLHOR SEFLG_DPSIDEPS_1980
#define SEFLG_JPLHOR_APPROX (512*1024) /* approximate JPL Horizons 1962 - today */
1024 | 512
我用 mac 1024 OR 512 的计算器试了一下,结果是 1536。这个结果正确吗?
是的,它是正确的。
512 =01000000000
1024=10000000000
1536=11000000000
OR-计算:
10000000000
|01000000000
=11000000000
一句话-是的。请注意,1024
和 512
在相同位置没有“1”位,因此对它们进行按位或运算的结果与将它们相加的结果相同。
是的,结果是正确的:事实上,OR-ing 1024 和 512 产生的数字与将它们相加得到的数字相同。
这是一个方便的 "shortcut" 对两个幂进行 OR 运算:因为它们的数字永远不会占据相同的位置,加法与 "OR" 相同。
当非零位置不重叠时,这里使用的原理与在除单个位置以外的所有位置添加零的小数相同:添加,比方说,6000+900+30+7 与将各个数字写到 6937 中,因为位值不会相互影响。 OR-ing 二进制中两个不同的幂等同于在被 OR-ed 的数字指定的位置写下所有 1。
请注意,表达式 (SEFLG_NOABERR|SEFLG_NOGDEFL)
是在编译时计算的,因此将其替换为 1536 不会产生任何 运行 时间改进。