-2

我有一组预先确定的值:

1000000000000000000000000000000000000000
100000000000000000000000000000000000000
10000000000000000000000000000000000000
1000000000000000000000000000000000000
100000000000000000000000000000000000
10000000000000000000000000000000000
1000000000000000000000000000000000
100000000000000000000000000000000
10000000000000000000000000000000
1000000000000000000000000000000
100000000000000000000000000000
10000000000000000000000000000
1000000000000000000000000000
100000000000000000000000000
10000000000000000000000000
1000000000000000000000000
100000000000000000000000
10000000000000000000000
1000000000000000000000
100000000000000000000
10000000000000000000
1000000000000000000
100000000000000000
10000000000000000
1000000000000000
100000000000000
10000000000000
1000000000000
100000000000
10000000000
1000000000
100000000
10000000
1000000
100000
10000
1000
100
10
1

我给了另一个值:

1000000100100000000000000000000000

我如何计算出给定的二进制值的组合是什么?

请注意,这些值有时只是预定义值中的 1 个,有时可能是全部。

对我来说看起来很简单,但我画的是空白!

干杯!

对于那些想要看到我的尝试的人来说……你去吧

.....



  $DBH = new PDO("dblib:host=$myServer;dbname=$SystemDB", $myUser, $myPass);
  $DBH1 = new PDO("dblib:host=$myServer;dbname=$TaxiHistoryDB", $myUser, $myPass);


  $sth = $DBH->prepare("SELECT dbo.Conditions.Name, dbo.Conditions.ConditionValue FROM dbo.Conditions Where dbo.Conditions.ConditionID > 0");
  $sth->execute();

  $result = $sth->fetchAll();
  print_r($result);
  echo "<br>";
  echo "<br>";
  $result = array_reverse($result);
  $STH1 = $DBH1->query("SELECT dbo.tblBooking.Conditions FROM dbo.tblBooking WHERE dbo.tblBooking.BookingID = '36661447'");

  $STH1->setFetchMode(PDO::FETCH_LAZY);

  while($row1 = $STH1->fetch()){
     $condition = $row1->Conditions;
     echo $condition;
     echo "<br>";
     echo base_convert($condition, 10, 2);
     echo "<br>";
     $value = $result['ConditionValue'];
     echo $value;
     foreach($result as $array) {

         $value = $array['ConditionValue']; 
         $binaryCondition = base_convert($condition, 10, 2);
         $binaryValue = base_convert($value, 10, 2);
         echo "<br>";
         echo $binaryValue;

       }//end foreach
    }//end while
4

2 回答 2

2

我会给你一个答案而不是解释它,因为它看起来你甚至没有尝试过!如果这是家庭作业,那么你得到它是有原因的。

$possible_bits = array(
'1000000000000000000000000000000000000000',
'100000000000000000000000000000000000000',
'10000000000000000000000000000000000000',
'1000000000000000000000000000000000000',
'100000000000000000000000000000000000',
'10000000000000000000000000000000000',
'1000000000000000000000000000000000',
'100000000000000000000000000000000',
'10000000000000000000000000000000',
'1000000000000000000000000000000',
'100000000000000000000000000000',
'10000000000000000000000000000',
'1000000000000000000000000000',
'100000000000000000000000000',
'10000000000000000000000000',
'1000000000000000000000000',
'100000000000000000000000',
'10000000000000000000000',
'1000000000000000000000',
'100000000000000000000',
'10000000000000000000',
'1000000000000000000',
'100000000000000000',
'10000000000000000',
'1000000000000000',
'100000000000000',
'10000000000000',
'1000000000000',
'100000000000',
'10000000000',
'1000000000',
'100000000',
'10000000',
'1000000',
'100000',
'10000',
'1000',
'100',
'10',
'1');

$test_number = '1000000100100000000000000000000000';
$test_number_lsb = bindec(substr($test_number, -32));
$test_number_msb = bindec(substr_replace($test_number, '', -33));

foreach(array_reverse($possible_bits) as $bit => $bit_value){
    $dec_value_lsb = bindec(substr($bit_value, -32));
    $dec_value_msb = bindec(substr_replace($bit_value, '', -33));    
    if($test_number_lsb & $dec_value_lsb || $test_number_msb & $dec_value_msb)
        echo $bit."\n";
}

我已将其更新为 32 位

于 2013-09-19T03:53:31.027 回答
0

看看按位运算符

<?php

$test = bindec(1000000100100000000000000000000000);

for ($i = 0; $i < 40; $i++)
    if (bindec($bit = pow(10, $i)) & $test)
        echo $bit . "\n";

这是一个 32 位版本:http ://codepad.org/nf545W2J

于 2013-09-19T06:16:36.260 回答