如何将byte [512]转换为1024字符串的长度

时间:2017-06-28 10:34:40

标签: c# .net byte

这段代码产生一个大小为512的数组,它转换一个最初长度为1024个字符并且有十六进制数据的字符串。

namespace Console\Controller\Component;
use Cake\Controller\Component\PaginatorComponent as BasePaginator;


class PaginatorComponent extends BasePaginator
{
    public function paginate($object, array $settings = [])
    {
        $query = null;
        if ($object instanceof QueryInterface) {
            $query = $object;
            $object = $query->repository();
        }

        $alias = $object->alias();
        $options = $this->mergeOptions($alias, $settings);
        $options = $this->validateSort($object, $options);
        $options = $this->checkLimit($options);

        $options += ['page' => 1, 'scope' => null];
        $options['page'] = (int)$options['page'] < 1 ? 1 : (int)$options['page'];
        list($finder, $options) = $this->_extractFinder($options);

        if (empty($query)) {
            $query = $object->find($finder, $options);
        } else {
            $query->applyOptions($options);
        }
        $cleanQuery = clone $query;
        // My Modification Starts Here
        $table      = $cleanQuery->repository();
        $results = $query->all();
        $numResults = count($results);

        $count = $numResults ? $cleanQuery->select([
            "count"=>$cleanQuery
                        ->func()
                        ->count($table->alias().'.'.$table->primaryKey())
        ])->first()->count : 0;
        // My Modification ends Here
        $defaults = $this->getDefaults($alias, $settings);
        unset($defaults[0]);

        $page = $options['page'];
        $limit = $options['limit'];
        $pageCount = (int)ceil($count / $limit);
        $requestedPage = $page;
        $page = max(min($page, $pageCount), 1);
        $request = $this->_registry->getController()->request;

        $order = (array)$options['order'];
        $sortDefault = $directionDefault = false;
        if (!empty($defaults['order']) && count($defaults['order']) == 1) {
            $sortDefault = key($defaults['order']);
            $directionDefault = current($defaults['order']);
        }

        $paging = [
            'finder' => $finder,
            'page' => $page,
            'current' => $numResults,
            'count' => $count,
            'perPage' => $limit,
            'prevPage' => $page > 1,
            'nextPage' => $count > ($page * $limit),
            'pageCount' => $pageCount,
            'sort' => key($order),
            'direction' => current($order),
            'limit' => $defaults['limit'] != $limit ? $limit : null,
            'sortDefault' => $sortDefault,
            'directionDefault' => $directionDefault,
            'scope' => $options['scope'],
        ];

        if (!$request->getParam('paging')) {
            $request->params['paging'] = [];
        }
        $request->params['paging'] = [$alias => $paging] + (array)$request->getParam('paging');

        if ($requestedPage > $page) {
            throw new NotFoundException();
        }

        return $results;
    }
}

我想知道如何反转这个,所以取一个字节[512]我想生成包含十六进制数据的1024长度字符串。

1 个答案:

答案 0 :(得分:0)

尝试

var result = string.Join("", 
                inputString.Select(c => String.Format("{0:X2}", Convert.ToInt32(c))));